C连接Mysql数据库代码_技术学院_宜昌市隼壹珍商贸有限公司

您好,欢迎访问宜昌市隼壹珍商贸有限公司

400 890 5375
当前位置: 主页 > 新闻动态 > 技术学院

C连接Mysql数据库代码

发布时间:2026-01-17  |  点击率:

复制代码 代码如下://vc工具中添加E:\WAMP\BIN\MYSQL\MYSQL5.5.8\LIB 路径 
 //在工程设置-》链接》库模块中添加 libmysql.lib  
#include <stdio.h> 
#include <time.h> 
#include <string.h> 
#include <winsock.h> 
#include "E:\wamp\bin\mysql\mysql5.5.8\include\mysql.h" 
void main(){  
       MYSQL *conn;  
       MYSQL_RES *res;  
       MYSQL_ROW row;  
       char *server ="localhost";  
       char *user ="root";  
       char *password="";  
       char *database="test";  
       char sql[1024]="select * from chinaren";  
       conn=mysql_init(NULL);  

       if(!mysql_real_connect(conn,server,user,password,database,0,NULL,0)){  
               fprintf(stderr,"%s\n",mysql_error(conn));  
               exit(1);  
       }  

       if(mysql_query(conn,sql)){  
               fprintf(stderr,"%s\n",mysql_error(conn));  
               exit(1);  
       }  

       res=mysql_use_result(conn);  

       while((row = mysql_fetch_row(res))!=NULL){  
               printf("%s\n",row[2]);  
       }  

       mysql_free_result(res);  
       mysql_close(conn);  
}

全国统一服务电话

400 890 5375

电子邮箱:879577@qq.com

公司地址:宜昌市西陵区黄河路5号三峡明珠10栋1051室

咨询微信

TEL:13680874598