emsApplication/applications/ems_datahubs/opmysql.h

43 lines
920 B
C
Raw Normal View History

2024-05-29 14:46:44 +08:00
#ifndef __MY_OPERATE_MYSQL__
#define __MY_OPERATE_MYSQL__
#include <string>
2024-11-15 18:22:43 +08:00
#ifdef _WIN32
# define _USING_MYSQL_51_LIB_
# include <WinSock2.h>
# include <mysql.h> //MySQL C API include file
#else
# ifdef __linux__
# include <mysql_connection.h>
# endif
#endif
2024-05-29 14:46:44 +08:00
class OpDatabase
{
protected:
OpDatabase();
public:
~OpDatabase();
static OpDatabase* getInstance();
void CloseDatabase();
2024-11-15 18:22:43 +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-05-29 14:46:44 +08:00
void InsertMessage(const std::string& ts, const std::string& msg_type, const std::string& fsu, const std::string& content, int topic, int dev_id);
protected:
2024-11-15 18:22:43 +08:00
#ifdef _WIN32
MYSQL* m_pDbConnection;
#else
# ifdef __linux__
sql::Connection* m_pDbConnection;
# endif
#endif
2024-05-29 14:46:44 +08:00
private:
static OpDatabase m_instance;
};
#endif