43 lines
920 B
C++
43 lines
920 B
C++
#ifndef __MY_OPERATE_MYSQL__
|
|
#define __MY_OPERATE_MYSQL__
|
|
|
|
#include <string>
|
|
|
|
|
|
#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
|
|
|
|
class OpDatabase
|
|
{
|
|
protected:
|
|
OpDatabase();
|
|
public:
|
|
~OpDatabase();
|
|
static OpDatabase* 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");
|
|
|
|
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:
|
|
#ifdef _WIN32
|
|
MYSQL* m_pDbConnection;
|
|
#else
|
|
# ifdef __linux__
|
|
sql::Connection* m_pDbConnection;
|
|
# endif
|
|
#endif
|
|
private:
|
|
static OpDatabase m_instance;
|
|
};
|
|
|
|
#endif
|