当前位置:Gxlcms > 数据库问题 > linux-c语言连接mysql

linux-c语言连接mysql

时间:2021-07-01 10:21:17 帮助过:4人阅读

<stdio.h> #include<stdlib.h> int main() { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *server = "localhost"; char *user = "root"; char *password = "123456"; char *database = "student"; conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } /* send SQL query */ if (mysql_query(conn, "SELECT * FROM info where sno=‘3‘")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } res = mysql_use_result(conn); /* output fields 1 and 2 of each row */ while ((row = mysql_fetch_row(res)) != NULL) printf("%s %s\n", row[0], row[1]); mysql_close(conn); return 0; }
技术分享

 

linux-c语言连接mysql

标签:

人气教程排行