C++访问MySQL #include "stdafx.h" #include #include #include int main(int argc,char* argv[])   {     char *user ="root", *pwd ="123456", *dbname = "chardb";     MYSQL  mysql;     MYSQL_RES  *mysql_ret;     MYSQL _ROW  mysql_row;     unsigned  long  num_rows;     int  ret;     mysql_init(&mysql);     if(mysql_real_connect(&mysql,NULL,user,pwd,dbname,0,NULL,0))     {       printf("连接成功!n");       ret  =  mysql_query(&mysql,"select  *  from  accounts");       if(!ret)       {         printf("查询成功!n");         mysql_ret  =  mysql_store_result(&mysql);         if(mysql_ret  !=  NULL)         {           printf("存储结果成功!n");           num_rows  =  mysql_num_rows(mysql_ret);           if(num_rows  !=  0)           {             printf("%dn",num_rows);             while(mysql_row  =  mysql_fetch_row(mysql_ret))             {               printf("%st%st%st%st%st%sn",mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5]);             }           }           else           {             exit(-1);           }           mysql_free_result(mysql_ret);           exit(0);         } _ROW  mysql_row;     unsigned  long  num_rows;     int  ret;     mysql_init(&mysql);     if(mysql_real_connect(&mysql,NULL,user,pwd,dbname,0,NULL,0))     {       printf("连接成功!n");       ret  =  mysql_query(&mysql,"select  *  from  accounts");       if(!ret)       {         printf("查询成功!n");         mysql_ret  =  mysql_store_result(&mysql);         if(mysql_ret  !=  NULL)         {           printf("存储结果成功!n");           num_rows  =  mysql_num_rows(mysql_ret);           if(num_rows  !=  0)           {             printf("%dn",num_rows);             while(mysql_row  =  mysql_fetch_row(mysql_ret))             {               printf("%st%st%st%st%st%sn",mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5]);             }           }           else           {             exit(-1);           }           mysql_free_result(mysql_ret);           exit(0);         }