无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

C/C++連接Mysql數(shù)據(jù)庫 | 數(shù)據(jù)庫增刪改查C++封裝 | 信息管理系統(tǒng)通

2023-06-09 00:24 作者:沒有溫度的茶  | 我要投稿

報錯Failed to connect to database : Error:This handle is already connected. Use a separate handle for each connection.

解決了。將代碼修改成這樣就不會報這個錯。#include <mysql.h>

#include <iostream>

#include <string>

using namespace std;


const char* host = "localhost";

const char* user = "root";

const char* pw = "123456";

const char* database_name = "database_test";

const int port = 3306;


typedef struct People

{

??int people_id;

??string?people_name;

??string?address_id;

} People;


int main()

{

??MYSQL* con = mysql_init(NULL);

??mysql_options(con, MYSQL_SET_CHARSET_NAME, "GBK");


??if (!mysql_real_connect(con, host, user, pw, database_name, port, NULL, 0))

??{

????fprintf(stderr, "Failed to connect to database : Error:%s\n", mysql_error(con));

????return -1;

??}


??People stu{ 1111,"吳彥祖","軟件工程2班" };

??char sql[1024];

??sprintf(sql, "insert into people (people_id,people_name,address_id) values(%d,'%s','%s')",

????stu.people_id, stu.people_name.c_str(), stu.address_id.c_str());

??if (mysql_query(con, sql))

??{

????fprintf(stderr, "Failed to insert data : Error:%s\n", mysql_error(con));

????mysql_close(con);

????return -1;

??}


??mysql_close(con);

??return 0;

}


C/C++連接Mysql數(shù)據(jù)庫 | 數(shù)據(jù)庫增刪改查C++封裝 | 信息管理系統(tǒng)通的評論 (共 條)

分享到微博請遵守國家法律
托里县| 渝中区| 乌兰县| 武定县| 安岳县| 商水县| 平原县| 乐亭县| 蓝田县| 益阳市| 吕梁市| 甘泉县| 台前县| 航空| 禹州市| 越西县| 萝北县| 渭源县| 刚察县| 嘉祥县| 黄大仙区| 西华县| 南雄市| 饶阳县| 邵阳县| 七台河市| 桐乡市| 彭州市| 苍梧县| 甘肃省| 扎鲁特旗| 依安县| 汶上县| 南漳县| 子洲县| 尚义县| 黄浦区| 高密市| 保山市| 华池县| 鄂州市|