ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
#### 图片 ![](https://box.kancloud.cn/9c1a5b91e66811d58e49b3199e9f1573_794x588.png) #### 代码 ~~~ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <winsock.h> #include <mysql.h> int main() { printf("Content-type:text/html\n\n"); for (int i = 0; i < 1; i++) { printf("hello c (%d) <br/>\n", i); } MYSQL *mysql = mysql_init(NULL); if (mysql_real_connect(mysql, "localhost", "root", "root", "xj2014", 3306, NULL, 0)) { printf("数据库连接成功\n"); if (mysql_set_character_set(mysql, "gbk")) { printf("编码设置失败:%s\n",mysql_error(mysql)); exit(1); } if (mysql_query(mysql, "select num,name,classs from userinfo limit 10")) { printf("查询出错:%s\n", mysql_error(mysql)); exit(1); }; MYSQL_RES* res = mysql_store_result(mysql); MYSQL_ROW row; while (row = mysql_fetch_row(res)) { printf("\n学号=%s\t姓名=%s\t班级=%s", row[0], row[1],row[2]); } mysql_free_result(res); mysql_close(mysql); } else { printf("数据库连接失败\n"); exit(1); } Sleep(500); return 0; } ~~~