在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#include "mysql.h" int _tmain(int argc, _TCHAR* argv[]) { MYSQL * mysql; mysql = mysql_init(NULL); if (mysql != NULL) { MYSQL* sql = mysql_real_connect(mysql, "localhost", "root", "moli19881021", "test", 3306, NULL, 0); if (sql != NULL) { int val = mysql_select_db(mysql, "test"); if (val != 0) { printf("mysql_select_db failed.\n"); mysql_close(mysql); getchar(); return 0; } printf("select db success.\n"); mysql->reconnect = 1; // 操作数据库 char tmp[512] = {0}; sprintf(tmp, "select * from test.info_test"); int rt = mysql_real_query(mysql, tmp, strlen(tmp)); if (rt != 0) { printf("query failed : %s\n", mysql_error(mysql)); mysql_close(mysql); getchar(); return 0; } // 显示结果 MYSQL_RES* res; res = mysql_store_result(mysql); MYSQL_ROW row ; while (row = mysql_fetch_row(res)) { for (int i = 0; i < mysql_num_fields(res); i ++) { printf("%s ", row[i]); } printf("\n"); } mysql_free_result(res); mysql_close(mysql); } } getchar(); return 0; }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论