From 4f045ac9062517afb8b0bbeb11f9758938725516 Mon Sep 17 00:00:00 2001
From: Administrator <3174665893@qq.com>
Date: 星期五, 08 十一月 2024 15:56:31 +0800
Subject: [PATCH] Merge branch 'master' of ssh://115.28.86.8:29418/~admin/昆仑_1025

---
 Server/王琨元/code/MysqlConn.cpp |   20 +++-----------------
 1 files changed, 3 insertions(+), 17 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..00003aa 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"
@@ -11,8 +11,6 @@
         cout << "Failed to initialize MySQL." << endl;
         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 +20,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 +50,6 @@
     }
     int paramCount = mysql_stmt_param_count(stmt);
     if (paramCount > 0) {
-        // 如果有参数,需要进行参数绑定等操作,这里暂不实现
         mysql_stmt_close(stmt);
         return false;
     }
@@ -91,6 +76,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 +90,7 @@
 // 查询数据库
 bool MysqlConn::query(string sql) {
     freeRes();
-    // 参数化查询优化后的安全检查
+     //参数化查询优化后的安全检查
     MYSQL_STMT* stmt = mysql_stmt_init(m_mysql);
     if (!stmt) {
         return false;

--
Gitblit v1.8.0