#include <iostream>
|
//#include <mysql.h>
|
#include <winsock2.h>
|
#include "mysql/include/mysql.h"
|
|
#include <memory>
|
#include <string>
|
#include <chrono>
|
#include <fstream>
|
#include <vector>
|
|
using namespace std;
|
|
#pragma comment(lib, "libmysql.lib")
|
#pragma comment(lib, "ws2_32.lib")
|
|
typedef long long ll;
|
/*
|
mysql_init() ³õʼ»¯MYSQL±äÁ¿
|
mysql_real_connect //Á¬½Óµ½Êý¾Ý¿â
|
mysql_real_query //Êý¾Ý¿â²éѯ
|
mysql_query(MYSQL*mysql,const char*query)
|
mysql_store_result/mysql_use_result //·µ»ØµÄ»ñÈ¡²éѯ½á¹ûÊý¾Ý
|
mysql_fetch_row//¶ÁÈ¡½á¹û¼¯Êý¾Ý
|
mysql_free_result//ÊͷŽá¹û¼¯£¬ÒÔ·ÀÄÚ´æÐ¹Â©
|
mysql_close//¹Ø±ÕÊý¾Ý¿âÁ¬½Ó
|
|
*/
|
class ConnectMysql
|
{
|
private:
|
std::chrono::steady_clock::time_point m_alivetime;// ¼Ç¼Á¬½ÓµÄ´æ»îÆðʼʱ¼äµã
|
MYSQL* m_conn;
|
MYSQL_RES* m_result;// ±£´æ²éѯ½á¹û
|
MYSQL_ROW m_mysqlRow;// ±£´æ²éѯ½á¹ûµÄijһÐÐ
|
|
void freeRes();// ÊͷŽá¹û¼¯
|
|
public:
|
ConnectMysql();
|
~ConnectMysql();
|
bool connect(const string user = "root", const string passwd = "1",
|
const string dbName = "AI_datas", string ip = "192.168.133.129", const unsigned short port = 3306);// Á¬½ÓÊý¾Ý¿â
|
bool update(const string sql) const;// ¸üÐÂÊý¾Ý¿â
|
bool query(const string sql);// ²éѯÊý¾Ý¿â
|
bool getRes();// ±éÀú²éѯ½á¹û¼¯£¬»ñÈ¡ÏÂÒ»ÐÐÊý¾Ý
|
string getValue(const int fieldIndex) const;// »ñÈ¡²éѯ½á¹û¼¯Ä³Ò»ÐеÄijһÁÐ
|
vector<vector<string>> getQueryResults(); // ²éѯ½á¹û
|
//bool selectDB(const string dbName) const;// Ñ¡ÔñÊý¾Ý¿â
|
//bool createDB(const string dbName) const;// ´´½¨Êý¾Ý¿â
|
|
void backupCurrentDBUsingShell(const string path); // ʹÓà Shell ½Å±¾±¸·ÝÊý¾Ý¿â
|
void backupCurrentDB(const string path); //±¸·ÝÊý¾Ý¿â
|
void backupCurrentTable(const string path, const string tableName);
|
bool transaction() const;// ¿ªÆôÊÂÎñ
|
bool commit() const;// Ìá½»ÊÂÎñ
|
bool rollback() const;// »Ø¹öÊÂÎñ
|
void refreashAliveTime();// ˢдæ»îʱ¼ä
|
ll getAliveTime();// »ñÈ¡´æ»îʱ¼ä£¬µ¥Î»£ººÁÃë
|
};
|