From 951c1d946422a5b3be42d2d0710590fa80e14de4 Mon Sep 17 00:00:00 2001
From: wangky <m1561510467@163.com>
Date: 星期四, 07 十一月 2024 17:32:22 +0800
Subject: [PATCH] 1

---
 Server/王琨元/code/MysqlConn.cpp |   19 +++----------------
 1 files changed, 3 insertions(+), 16 deletions(-)

diff --git "a/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.cpp" "b/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.cpp"
index 071cf5f..1749d07 100644
--- "a/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.cpp"
+++ "b/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.cpp"
@@ -12,7 +12,6 @@
         return;
     }
     // 设置字符集
-    if (m_mysql) mysql_set_character_set(m_mysql, "gbk");
     // 使用写死的参数连接数据库
     m_mysql = mysql_real_connect(m_mysql, "127.0.0.1", "root", "123456", "mayi_kunlun", 3306, nullptr, 0);
     if (!m_mysql) {
@@ -22,25 +21,13 @@
         m_mysql = nullptr;
     }
     // 初始化 row_ 和 res_
+    if (m_mysql) mysql_set_character_set(m_mysql, "gbk");
     m_row = nullptr;
     m_res = nullptr;
 }
 bool MysqlConn::isConnected() {
     return m_mysql != nullptr;
 }
-// 连接数据库
-//bool MysqlConn::connect() {
-//    string ip = "127.0.0.1";
-//    string userName = "root";
-//    string passwd = "123456";
-//    string db = "mayi_kunlun";
-//    int port = 3306;
-//    m_mysql = mysql_real_connect(mysql_, ip.c_str(), userName.c_str(), passwd.c_str(), db.c_str(), port, nullptr, 0);
-//    if (!m_mysql) {
-//        return false;
-//    }
-//    return true;
-//}
 
 // 释放资源
 MysqlConn::~MysqlConn() {
@@ -64,7 +51,6 @@
     }
     int paramCount = mysql_stmt_param_count(stmt);
     if (paramCount > 0) {
-        // 如果有参数,需要进行参数绑定等操作,这里暂不实现
         mysql_stmt_close(stmt);
         return false;
     }
@@ -91,6 +77,7 @@
     //int col_cnt = m_mysql->field_count;
     int col_cnt = mysql_field_count(m_mysql);
     cout << col_cnt << endl;
+    MYSQL_ROW m_row;
     while (m_row = mysql_fetch_row(m_res)) {
         vector<string> tmp;
         for (int i = 0; i < col_cnt; i++) {
@@ -104,7 +91,7 @@
 // 查询数据库
 bool MysqlConn::query(string sql) {
     freeRes();
-    // 参数化查询优化后的安全检查
+     //参数化查询优化后的安全检查
     MYSQL_STMT* stmt = mysql_stmt_init(m_mysql);
     if (!stmt) {
         return false;

--
Gitblit v1.8.0