#pragma once
|
|
#include <string>
|
#include <WinSock2.h>
|
#include <mysql.h>
|
#include <string.h>
|
#include <chrono>
|
|
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_;
|
};
|