From 2ba7e15157b43a06f100602d3f3257cb3a06f9e5 Mon Sep 17 00:00:00 2001 From: lzx <2246256235@qq.com> Date: 星期四, 07 十一月 2024 15:07:04 +0800 Subject: [PATCH] erge branch 'master' of ssh://115.28.86.8:29418/~admin/昆仑_1025 --- Server/王琨元/code/MysqlConn.h | 96 ++++++++++++++++++++--------------------------- 1 files changed, 41 insertions(+), 55 deletions(-) diff --git "a/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h" "b/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h" index 0dbbea9..53bb3fc 100644 --- "a/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h" +++ "b/Server/\347\216\213\347\220\250\345\205\203/code/MysqlConn.h" @@ -1,63 +1,49 @@ #pragma once -#include<iostream> -#include <memory> -#include <string> -#include <mysql.h> -#include <chrono> // 时钟 -#include <fstream> -#pragma comment(lib, "./lib/libmysql.lib") // 加载数据库库文件 -using namespace std; -using namespace chrono; -typedef long long ll; +#include <string> +#include <WinSock2.h> +//#include <mysql.h> +#include "MySQL/include/mysql.h" +#include <string.h> +#include <chrono> + +#pragma comment(lib,"./MySQL/lib/libmysql.lib") class MysqlConn { -private: - // 绝对时钟 - steady_clock::time_point m_alivetime; - // 连接 - MYSQL* m_conn; - // 查询的结果集 - MYSQL_RES* m_result; - // 单记录结果集 - MYSQL_ROW m_mysqlRow; - - // 结果集释放 - void freeRes(); - // 导出某一张表中的数据 - void backupCurrentTable(const string path, const string tableName); public: - // 初始化数据库 + // 锟斤拷始锟斤拷锟斤拷锟斤拷 MysqlConn(); - // 数据库连接释放 - ~MysqlConn(); - // 连接数据库, 需提供用户 密码 数据库名称 ip 端口 - bool connect(const string user, const string passwd, \ - const string dbName, string ip, \ - const unsigned short port = 3306U); - // 更新数据库:增删改操作 - bool update(const string sql) const; - // 查询数据库 - bool query(const string sql); - // 遍历查询结果集 - bool getRes(); - // 获取结果集中的字段值 - string getValue(const int fieldIndex) const; - // 切换数据库 - bool selectDB(const string dbName) const; - // 建库 - //bool createDB(const string dbName) const; - // 备份某个库 - void backupCurrentDB(const string path); - // 事务操作 - bool transaction() const; - // 提交事务 - bool commit() const; - // 事务回滚 - bool rollback() const; - // 刷新起始的空闲时间点 - void refreashAliveTime(); - // 计算存活总时长 - ll getAliveTime(); + // 锟斤拷锟斤拷锟斤拷锟捷匡拷 + bool connect(std::string ip, std::string userName, std::string passwd, std::string db , int port = 3306); + // 锟酵凤拷锟斤拷源 + ~MysqlConn( ); + // 锟斤拷锟斤拷锟斤拷锟捷匡拷 ( insert update delete ) + bool update(std::string sql); + // 锟斤拷询锟斤拷锟捷匡拷 + bool query(std::string sql); + // 锟矫碉拷锟斤拷锟斤拷锟斤拷 + bool getResult(); + // 锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟街讹拷 + std::string getField(int index); + // 锟斤拷锟斤拷锟斤拷锟斤拷 + bool transaction(); + // 锟结交锟斤拷锟斤拷 + bool commit( ); + // 锟斤拷锟斤拷锟截癸拷 + bool rollback(); + + void refreshActiveTime( ); // 刷锟铰伙拷跃时锟斤拷 + long long getActiveTime(); // 锟斤拷取锟斤拷前锟斤拷跃锟斤拷时锟斤拷锟斤拷锟斤拷 + // 锟斤拷全校锟斤拷锟接匡拷 + bool isSqlSafe(const std::string& sql); + +private: + + void freeRes(); + MYSQL* mysql_ = NULL ; + MYSQL_RES* res_ = NULL; + MYSQL_ROW row_ = nullptr; + std::chrono::steady_clock::time_point activeTime_; }; + -- Gitblit v1.8.0