select1.c
来自「在Linux操作系统下的C语言进行MySQL进行增删改查」· C语言 代码 · 共 49 行
C
49 行
#include <stdio.h>#include <stdlib.h>#include "/usr/include/mysql/mysql.h"int main(int argc,char *argv[]){ MYSQL my_connection; MYSQL_RES *res_ptr; MYSQL_ROW sqlrow; int res; 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 where id=4"); 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)); while((sqlrow=mysql_fetch_row(res_ptr))) { printf("Fetched data...\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 + =
减小字号Ctrl + -
显示快捷键?