2024-09-21 13:57:16 +08:00
|
|
|
#ifndef MYSQLUTILS_H
|
|
|
|
#define MYSQLUTILS_H
|
|
|
|
|
|
|
|
#include <string>
|
2024-10-11 14:20:12 +08:00
|
|
|
|
|
|
|
#ifdef _USING_QT_MYSQL_CONNECTOR_
|
|
|
|
#include <QtSql/QSqlDatabase>_
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _USING_MYSQL_CONNECTOR_
|
|
|
|
#include <cppconn/connection.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _USING_MYSQL_51_LIB_
|
|
|
|
#include <WinSock2.h>
|
|
|
|
#include <mysql.h> // MySQL C API 头文件
|
|
|
|
#endif
|
2024-09-21 13:57:16 +08:00
|
|
|
|
|
|
|
class MysqlUtils
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
MysqlUtils();
|
|
|
|
public:
|
|
|
|
~MysqlUtils();
|
|
|
|
|
|
|
|
static MysqlUtils* getInstance();
|
|
|
|
|
|
|
|
void CloseDatabase();
|
2024-10-11 14:20:12 +08:00
|
|
|
bool OpenDatabase(const std::string& server = "127.0.0.1", int dbport = 3306, const std::string& dbuser = "root", const std::string& dbpasswd = "Hj57471000", const std::string& database="hjems");
|
2024-09-21 13:57:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
2024-10-11 14:20:12 +08:00
|
|
|
#ifdef _USING_QT_MYSQL_CONNECTOR_
|
|
|
|
QSqlDatabase m_DbConnection;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _USING_MYSQL_CONNECTOR_
|
|
|
|
sql::Connection* m_DbConnection;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _USING_MYSQL_51_LIB_
|
|
|
|
MYSQL* m_DbConnection;
|
|
|
|
#endif
|
|
|
|
|
2024-09-21 13:57:16 +08:00
|
|
|
static MysqlUtils m_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MYSQLUTILS_H
|