mysql
来源:互联网 发布:淘宝客提现规则 编辑:程序博客网 时间:2024/06/03 23:46
如何用C语言去访问和查询mysql数据库数据? 第二节 (2012-03-23 21:23:57)转载▼标签: mysql linux c语言连接mysql 分类: MYSQL下面的代码是用C语言连接数据的程序:其中包括连接、查询#include #include #include #include int main(int argc,char *argv[]){MYSQL my_connection;MYSQL_RES *res_ptr;MYSQL_FIELD *fd;MYSQL_ROW sqlrow;int i,j,k;int res;char array[25][25];mysql_init(&my_connection);if(mysql_real_connect(&my_connection,"localhost","root","123456","sg",0,NULL,CLIENT_FOUND_ROWS)){printf("connection success\n");res=mysql_query(&my_connection,"select * from electricity_record");if(res){printf("select error:%S\n",mysql_error(&my_connection));}else{res_ptr=mysql_store_result(&my_connection);if(res_ptr){printf("Retrieved %lu Rows\n",(unsigned long)mysql_num_rows(res_ptr));for(i=0;fd=mysql_fetch_field(res_ptr);i++)strcpy(array[i],fd->name);printf("the information\n");j=mysql_num_fields(res_ptr);for(i=0;i<j;i++)printf("%s\t",array[i]);printf("\n");while(sqlrow=mysql_fetch_row(res_ptr)){for(i=0;i<j;i++){printf("%s\t",sqlrow[i]);}printf("\n");}if(mysql_errno(&my_connection)){fprintf(stderr,"Retrive error:%s\n",mysql_error(&my_connection));}}mysql_free_result(res_ptr);}mysql_close(&my_connection);}else{fprintf(stderr,"Connection failed\n");if(mysql_errno(&my_connection)){fprintf(stderr,"connection error %d:%s\n",mysql_errno(&my_connection),mysql_error(&my_connection));}}return EXIT_SUCCESS;}
http://blog.sina.com.cn/s/blog_609fa94401010jyn.html
- Mysql
- MySql
- MYSQL
- MySQL
- mysql
- mysql
- mysql
- mysql
- Mysql
- Mysql
- mysql
- MySQL
- mysql
- Mysql
- mysql
- mysql
- mysql
- mySQL
- 关于struts2中ModelDriven的笔记
- linux学习笔记0.2---gstreamer命令
- Spring简介
- oracle 表空间查看
- PAT Advanced 1012
- mysql
- iOS 内存管理 (有ARC)
- 使用HelloCharts开源图表库制作柱状图
- 以此作为自己 python blog 里程的开始
- EditText限制输入金额(价格)格式
- 淘宝核心系统团队的产品线
- eclipse修改dynamic web module version
- 埃拉托斯特尼筛法求素数表
- 用户控件添加贝塞尔 曲线不显示问题