123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "pch.h"
- #include "HtlMsql.h"
- HtlMysql::HtlMysql()
- {
- p_sql = new MYSQL;
- mysql_init(p_sql);
-
- }
- HtlMysql::~HtlMysql()
- {
- mysql_close(p_sql);
- }
- HtlMysql* HtlMysql::GetInstance()
- {
- static HtlMysql htlmysql;
- return &htlmysql;
- }
- bool HtlMysql::Connect(DBINFO& Dbinfo)
- {
- if (mysql_real_connect(p_sql, Dbinfo.server_address, Dbinfo.user_name, Dbinfo.password, Dbinfo.database_name, Dbinfo.server_port, NULL, 0))
- {
- const char* aaa = "SET NAMES 'GB2312'";
- mysql_query(p_sql, aaa);
- p_sql->reconnect = true;
- return true;
- }
- else
- {
- return false;
- }
- }
- const char* HtlMysql::GetErrorInformation()
- {
- return mysql_error(p_sql);
- }
- bool HtlMysql::ExecutiveCommand(const char* SQLCommand)
- {
- if (mysql_ping(p_sql) == 0) {
- if(!mysql_query(p_sql, SQLCommand))
- {
- return false;
- }
- }
-
- return true;
- }
- MYSQL_RES* HtlMysql::GetResultSet()
- {
- return p_res = mysql_store_result(p_sql);
- }
|