240717班级,工业化控制系统,煤矿相关行业,昆仑系统
gong
2024-11-06 828ba1dcdd1fa803dddf94f4f1643452d5efa703
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
 
#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
{
public:
    // ³õʼ»¯Á¬½Ó
    MysqlConn();
    // Á¬½ÓÊý¾Ý¿â
    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_;
};