Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55595
  • 博文数量: 33
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 188
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-23 19:19
文章分类

全部博文(33)

文章存档

2015年(22)

2014年(11)

我的朋友

分类: C/C++

2014-12-30 16:40:12

来源: http://blog.csdn.net/afeiluo/article/details/7756518

#include

#include

int main(int argc,char **argv){
   MYSQL mysql_conn;
   MYSQL_RES *mysql_result;
   MYSQL_ROW mysql_row;
   char execsql[256];
   int f1,f2,num_row,num_col;
   
   if(mysql_init(&mysql_conn)!=NULL)
    {

        if(mysql_real_connect(&mysql_conn,"localhost","root","111111","test",MYSQL_PORT,NULL,0)!=NULL)
          {
              printf("connect success!!!\n");
              sprintf(execsql,"select * from info");
              if(mysql_query(&mysql_conn,execsql)==0)
              {
                 printf("query success!\n");
                 mysql_result=mysql_store_result(&mysql_conn);
                 num_row=mysql_num_rows(mysql_result);
                 num_col=mysql_num_fields(mysql_result);
                 printf("row: %d,col: %d\n",num_row,num_col);
                    for(f1=0;f1
                       {
                          mysql_row=mysql_fetch_row(mysql_result);
                            for(f2=0;f2
                              {
                                printf("[Row %d,Col %d]==>[%s]\n",f1,f2,mysql_row[f2]);
                              }
                       }
             }else
              {
                 printf("query error!!!\n");
              } 
        }else
          {
             printf("connect failed\n");
          }
  }else
     {
        printf("initial failed\n");
     }
     mysql_free_result(mysql_result);
     mysql_close(&mysql_conn);
     return 0;
}
编译: gcc xxx.c -o yyy I/usr/include/mysql/  -L/usr/lib/mysql/ -lmysqlclient
阅读(281) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~