📄 select2all.c
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "/usr/include/mysql/mysql.h"int main(int argc,char *argv[]){ MYSQL my_connection; MYSQL_RES *res_ptr; MYSQL_ROW sqlrow; MYSQL_FIELD *fd; char filename[25][25]; int res; int i,j,k; mysql_init(&my_connection); if(mysql_real_connect(&my_connection,"localhost","root","123456","peims",0,NULL,CLIENT_FOUND_ROWS)) { printf("connection success\n"); res=mysql_query(&my_connection,"select * from student"); 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(filename[i],fd->name); /*输出各条记录*/ printf("下面是检索出的各条信息\n"); j=mysql_num_fields(res_ptr); for(i=0;i<j;i++) printf("%s\t",filename[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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -