#### 图片
![](https://box.kancloud.cn/9c1a5b91e66811d58e49b3199e9f1573_794x588.png)
#### 代码
~~~
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
int main() {
printf("Content-type:text/html\n\n");
for (int i = 0; i < 1; i++) {
printf("hello c (%d)
\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;
}
~~~