emsApplication/applications/emsConfigurer/mysqlutils.h

49 lines
935 B
C++

#ifndef MYSQLUTILS_H
#define MYSQLUTILS_H
#include <string>
#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
class MysqlUtils
{
protected:
MysqlUtils();
public:
~MysqlUtils();
static MysqlUtils* getInstance();
void CloseDatabase();
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");
private:
#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
static MysqlUtils m_instance;
};
#endif // MYSQLUTILS_H