initialize m_conn
This commit is contained in:
parent
5fd0a88a80
commit
fed816d255
3 changed files with 11 additions and 9 deletions
|
@ -93,7 +93,7 @@ class MySQLBackend : public StorageBackend
|
|||
private:
|
||||
bool exec(const std::string &query);
|
||||
|
||||
MYSQL *m_conn;
|
||||
MYSQL m_conn;
|
||||
Config *m_config;
|
||||
std::string m_prefix;
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ default_avatar=catmelonhead.jpg
|
|||
#backend_config=backend_logging.cfg # log4cxx/log4j logging configuration file for backends
|
||||
|
||||
[database]
|
||||
type = none # or "none" without database backend
|
||||
type = mysql # or "none" without database backend
|
||||
database = test.sql
|
||||
prefix=icq
|
||||
|
|
|
@ -66,24 +66,26 @@ static LoggerPtr logger = Logger::getLogger("MySQLBackend");
|
|||
|
||||
MySQLBackend::MySQLBackend(Config *config) {
|
||||
m_config = config;
|
||||
m_conn = NULL;
|
||||
mysql_init(&m_conn);
|
||||
m_prefix = CONFIG_STRING(m_config, "database.prefix");
|
||||
}
|
||||
|
||||
MySQLBackend::~MySQLBackend(){
|
||||
if (m_conn) {
|
||||
mysql_close(m_conn);
|
||||
}
|
||||
mysql_close(&m_conn);
|
||||
}
|
||||
|
||||
bool MySQLBackend::connect() {
|
||||
LOG4CXX_INFO(logger, "Connecting database " << CONFIG_STRING(m_config, "database.database"));
|
||||
if (!mysql_real_connect(m_conn, CONFIG_STRING(m_config, "database.server").c_str(),
|
||||
LOG4CXX_INFO(logger, "Connecting MySQL server " << CONFIG_STRING(m_config, "database.server") << ", user " <<
|
||||
CONFIG_STRING(m_config, "database.user") << ", database " << CONFIG_STRING(m_config, "database.database") <<
|
||||
", port " << CONFIG_INT(m_config, "database.port")
|
||||
);
|
||||
|
||||
if (!mysql_real_connect(&m_conn, CONFIG_STRING(m_config, "database.server").c_str(),
|
||||
CONFIG_STRING(m_config, "database.user").c_str(),
|
||||
CONFIG_STRING(m_config, "database.password").c_str(),
|
||||
CONFIG_STRING(m_config, "database.database").c_str(),
|
||||
CONFIG_INT(m_config, "database.port"), NULL, 0)) {
|
||||
LOG4CXX_ERROR(logger, "Can't connect database: " << mysql_error(m_conn));
|
||||
LOG4CXX_ERROR(logger, "Can't connect database: " << mysql_error(&m_conn));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue