mysql connect by c++
#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#define host "localhost"
#define username "root"
#define password "123"
#define database "oa"
MYSQL *conn;
int main()
{
MYSQL_RES *res_set;
MYSQL_ROW row;
unsigned int i,ret;
FILE *fp;
MYSQL_FIELD *field;
unsigned int num_fields;
conn = mysql_init(NULL);
ret = mysql_options(conn, MYSQL_SET_CHARSET_NAME, "gbk");
mysql_real_connect(conn,host,username,password,database,0,NULL,0);
fp = fopen ( "t_sys_power.out","w");
fprintf(fp,"char set %s\n", mysql_character_set_name(conn));
mysql_query(conn,"SELECT * from t_sys_power ");//WHERE a1='abc'");
res_set = mysql_store_result(conn);
while((field = mysql_fetch_field(res_set)))
{
printf("field name %s\n", field->name);
}
num_fields = mysql_num_fields(res_set);
for(i = 0; i < num_fields; i++)
{
field = mysql_fetch_field_direct(res_set, i);
printf("Field %u is %s\n", i, field->name);
}
while ((row = mysql_fetch_row(res_set)) != NULL)
{
for (i=0; i<mysql_num_fields(res_set); i++)
{
fprintf(fp,"%s\n",row[i] != NULL ? row[i] : "NULL");
}
}
mysql_close(conn);
fclose(fp);
return 0;
}
//Ñ¡Ôñ->Ŀ¼£ºinclude:C:\PROGRAM FILES\MYSQL\MYSQL SERVER 5.0\INCLUDE£¨compiler option,directories,c++include)
//Ñ¡Ôñ->Ŀ¼£ºlib :C:\PROGRAM FILES\MYSQL\MYSQL SERVER 5.0\LIB\OPT(compiler option,directories,libraies)
//¹¤³Ì£ºÉèÖãºlink:libmysql.lib(updateÏÂÔØlibmysql,°²×°Ö®ºó£¬project,projcect option,parameters,linkerÖÐÊäÈë-lmysql
)
//libmysql.dll¿½±´µ½¿ÉÖ´ÐÐÎļþÏàͬĿ¼£¬»òÕßϵͳĿ¼ÏÂ
Ïà¹ØÎĵµ£º
ÔÚ³ÌÐò¿ª·¢ÖУ¬ÓÐʱ»á±»×Ö·ûÂÒÂëµÄÎÊÌâËùÀ§ÈÅ¡£¶Ô´Ë£¬±ØÐëÀí½â MySQL µÄ×Ö·û¼¯±àÂëÉèÖõÄÔÀí£ºÔÚMySQLÖУ¬Ä¬ÈÏʹÓõÄÊÇlartin1£¬Ò²¾ÍÊÇISO8859-1×Ö·û¼¯±àÂë¡£ÕâÊÇÒ»ÖÖ8λµÄ±àÂ룬ÊÊÓÃÓÚËùÓÐÎ÷Å·×Ö·û¡£¶ø¶ÔÓÚºº×ÖµÈÊDz»ºÏÊʵġ£×îºÃ¡¢×îͨÓõıàÂë¸ñʽÊÇutf-8£¬UTF-8£¨8 λԪ Universal Cha ......
MySQLÓкܶà¿ÉÒÔµ¼ÈëÊý¾ÝµÄ·½·¨£¬È»¶øÕâЩֻÊÇÊý¾Ý´«ÊäÖеÄÒ»°ë£¬ÁíÍâµÄÒ»°ãÊÇ´ÓMySQLÊý¾Ý¿âÖе¼³öÊý¾Ý¡£ÓÐÐí¶àµÄÔÒòÎÒÃÇÐèÒªµ¼³öÊý¾Ý¡£Ò»¸öÖØ
ÒªµÄÔÒòÊÇÓÃÓÚ±¸·ÝÊý¾Ý¿â¡£Êý¾ÝµÄÔì¼Û³£³£ÊÇ°º¹óµÄ£¬ÐèÒª½÷É÷´¦ÀíËüÃÇ¡£¾³£µØ±¸·Ý¿ÉÒÔ°ïÖú·ÀÖ¹±¦¹óÊý¾ÝµØ¶ªÊ§£»ÁíÍâÒ»¸öÔÒòÊÇ£¬Ò²ÐíÄúÏ£Íûµ¼³öÊý¾ÝÀ´¹²
Ïí¡£ ÔÚÕâ¸öÐÅÏ¢¼¼Ê ......
ÔÚÖ÷Íâ¼ü±í´æÔÚ¹ØϵµÄʱºòÈç¹û¼ÓÉÏ"lazy=true"µÄ»°£¬Ôò±íÃ÷ÑÓ³Ù£¬¼´Ö»²éѯÖ÷±íÖеÄÄÚÈÝ£¬¶ø²»²éѯÍâ¼ü±íÖеÄÄÚÈÝ¡£
Àý£º
<hibernate-mapping>
<class name="com.pojo.Sortp" table="sortp" catalog="shjdc">
<id name="id" type= ......
Ò»¡¢MYSQL´æ´¢ÒýÇæ´óÈ«£º
·MyISAM£ºÄ¬ÈϵÄMySQL²å¼þʽ´æ´¢ÒýÇ棬ËüÊÇÔÚWeb¡¢Êý¾Ý²Ö´¢ºÍÆäËûÓ¦Óû·¾³ÏÂ×ʹÓõĴ洢ÒýÇæÖ®Ò»¡£×¢Ò⣬ͨ¹ý¸ü¸ÄSTORAGE_ENGINEÅäÖñäÁ¿£¬Äܹ»·½±ãµØ¸ü¸ÄMySQL·þÎñÆ÷µÄĬÈÏ´æ´¢ÒýÇæ¡£
·InnoDB£ºÓÃÓÚÊÂÎñ´¦ÀíÓ¦ÓóÌÐò£¬¾ßÓÐÖÚ¶àÌØÐÔ£¬°üÀ¨ACIDÊÂÎñÖ§³Ö¡£
·BDB£º¿ÉÌæ´úI ......
Ò»:mysqlÀïÄ¿Ç°Ö»Ö§³Ö4ÖÖË÷Òý·Ö±ðÊÇ:b-tree,full-text,hashÒÔ¼°r-treeË÷Òý b-treeË÷ÒýÓ¦¸ÃÊÇmysqlÀï×î¹ã·ºµÄË÷ÒýµÄÁË,³ýÁËarchive,»ù±¾ËùÓеĴ洢ÒýÇ涼֧³ÖËü. 1.b-treeÔÚmyisamÀïµÄÐÎʽºÍinnodbÉÔÓв»Í¬ ÔÚinnodbÀïÃæÓÐÁ½ÖÖÐÎ̬:ÆäÒ»ÊÇprimary keyÐÎ̬Æäleaf nodeÀï´æ·ÅµÄÊÇÊý¾Ý.¶øÇÒ²»½ö´æ·ÅÁËË÷Òý¼üµÄÊý¾Ý,»¹´æ·ÅÁËÆ ......