longzhiwen

参考范例:

···

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<mysql.h>
#define MAX_COLUMN_LEN 32
int main(int argc , char *argv[])
{
MYSQL db;
MYSQL_RES *res;
MYSQL_ROW row;

//初始化数据库
mysql_init(&db);
//连接数据库
if(mysql_real_connect(&db,"127.0.0.1","root","huawei","information_schema",0,NULL,0))
{
printf("connect!!!\n");
}

//查询
if (mysql_real_query(&db, "select * from CHARACTER_SETS", (unsigned long)strlen("select * from CHARACTER_SETS")))
{
printf("mysql_real_query failed\n");
return 0;
}

// 存储结果集
res = mysql_store_result(&db);
if (NULL == res)
{
printf("mysql_store_result failed\n");
return 0;
}

// 重复读取行,并输出第一个字段的值,直到row为NULL
while (row = mysql_fetch_row(res))
{
printf("%s %s %s %s\n",row[0], row[1], row[2], row[3]);
}

// 释放结果集
mysql_free_result(res);
// 关闭Mysql连接
mysql_close(&db);


return 0;
}

···

分类:

技术点:

相关文章:

  • 2021-12-06
  • 2021-08-28
  • 2021-09-06
  • 2021-12-09
  • 2021-11-14
  • 2021-12-05
  • 2021-12-09
  • 2021-12-09
猜你喜欢
  • 2021-12-09
  • 2021-12-10
  • 2021-12-09
  • 2022-01-19
  • 2021-12-09
  • 2021-07-14
  • 2021-10-12
相关资源
相似解决方案