240717班级,工业化控制系统,煤矿相关行业,昆仑系统
lzx
2024-11-07 6703c96aa242966e17757c057906289715bd3ab9
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_;
};