From cec6937344e179a6db50c6386b24afcff165561f Mon Sep 17 00:00:00 2001 From: zyf <2786722087@qq.com> Date: 星期三, 02 四月 2025 09:21:04 +0800 Subject: [PATCH] zyf_0402_log --- Server/张怡帆/code/Database_Package.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+), 0 deletions(-) diff --git "a/Server/\345\274\240\346\200\241\345\270\206/code/Database_Package.cpp" "b/Server/\345\274\240\346\200\241\345\270\206/code/Database_Package.cpp" new file mode 100644 index 0000000..7f27a86 --- /dev/null +++ "b/Server/\345\274\240\346\200\241\345\270\206/code/Database_Package.cpp" @@ -0,0 +1,94 @@ +锘�// Database_Package.cpp : 姝ゆ枃浠跺寘鍚� "main" 鍑芥暟銆傜▼搴忔墽琛屽皢鍦ㄦ澶勫紑濮嬪苟缁撴潫銆� +// + +#include <iostream> +//#include <mysql.h> +#include <winsock2.h> +#include "mysql/include/mysql.h" + +#include <memory> +#include <string> +#include <chrono> +#include <fstream> +#include "ConnectionPool.h" + +using namespace std; + +/* +#define M_MYSQL_DNAME AI_datas +#define M_MYSQL_IP 192.168.133.129 +#define M_MYSQL_PORT 3306 +#define M_MYSQL_USER root +#define M_MYSQL_PASSWD 1 +#define M_MYSQL_PATH D:\\PROGECT_0214 +*/ + +void testDatabaseConnection() +{ + // 鍒涘缓杩炴帴姹犲璞� + ConnectionPool* pool = ConnectionPool::getInstance(); + + // 浠庤繛鎺ユ睜涓幏鍙栬繛鎺� + shared_ptr<ConnectMysql> conn = pool->getConnection(); + if (conn == nullptr) + { + cerr << "鏈彇寰楁暟鎹簱杩炴帴锛�" << endl; + return; + } + cout << "杩炴帴鎴愬姛" << endl; + + // 娴嬭瘯鏇存柊鍔熻兘 + string sql = "INSERT INTO employee_info (employee_name, employee_age, employee_sex, employee_bir, employee_password, employee_email, employee_phone, employee_department)VALUES('鏈辩悰', 20, '鐢�', '1999-09-09', '123456', '123456@123.com', '12345678901', 'asdf')"; + if (conn->update(sql)) + { + cout << "鏇存柊鎴愬姛锛�" << endl; + } + else + { + cerr << "鏇存柊澶辫触锛�" << endl; + } + + // 娴嬭瘯鏌ヨ鍔熻兘 + sql = "SELECT * FROM employee_info"; + if (conn->query(sql)) + { + cout << "姝e湪鏌ヨ..." << endl; + // 鑾峰彇鏌ヨ缁撴灉 + vector<vector<string>> results = conn->getQueryResults(); + // 澶勭悊鏌ヨ缁撴灉 + for (const auto& row : results) + { + for (const auto& field : row) + { + cout << field << "\t"; + } + cout << endl; + } + } + else + { + cerr << "鏌ヨ澶辫触锛�" << endl; + } + + // 瀹炵幇澶囦唤鍔熻兘 + string backupPath = "D:\\PROGECT_0214\\"; // 澶囦唤璺緞锛屼綘鍙互鏍规嵁闇�瑕佷慨鏀� + cout << "寮�濮嬪浠芥暟鎹簱..." << endl; + conn->backupCurrentDB(backupPath); + cout << "鏁版嵁搴撳浠藉畬鎴愶紒" << endl; + + cout << "寮�濮嬪浠借〃 employee_info..." << endl; + conn->backupCurrentTable(backupPath, "employee_info"); + cout << "琛� employee_info 澶囦唤瀹屾垚锛�" << endl; + // 浣跨敤shell鑴氭湰澶囦唤鏁版嵁搴� +//string backupPath = "D:\\PROGECT_0214\\"; // 澶囦唤璺緞锛屼綘鍙互鏍规嵁闇�瑕佷慨鏀� +//cout << "寮�濮嬩娇鐢╯hell鑴氭湰澶囦唤鏁版嵁搴�..." << endl; +//conn->backupCurrentDBUsingShell(backupPath); +//cout << "鏁版嵁搴撳浠藉畬鎴愶紒" << endl; +} + +int main() +{ + testDatabaseConnection(); + return 0; +} + -- Gitblit v1.8.0