当前位置: 技术问答>linux和unix
程序连接mySQL时的问题。
来源: 互联网 发布时间:2017-01-16
本文导语: 头文件: MYSQL *m_pmySQL; CDatabase_mySQL::CDatabase_mySQL() { m_pmySQL = NULL; //初始化 } void CDatabase_mySQL::CloseDatabase(void) { if (m_pmySQL) { mysql_close(m_pmySQL); m_pmySQL = NULL; } } bool CDatabase_mySQL::OpenDatabase(char *pHostName, char *p...
头文件:
MYSQL *m_pmySQL;
CDatabase_mySQL::CDatabase_mySQL()
{
m_pmySQL = NULL; //初始化
}
void CDatabase_mySQL::CloseDatabase(void)
{
if (m_pmySQL)
{
mysql_close(m_pmySQL);
m_pmySQL = NULL;
}
}
bool CDatabase_mySQL::OpenDatabase(char *pHostName, char *pDatabaseName, char *pUserName, char *pPwd)
{
CloseDatabase();
if ((m_pmySQL = mysql_init(NULL)) == NULL)
{
return false;
}
if (mysql_real_connect(m_pmySQL, "localhost", "root", "", "testdb", 0, NULL, 0))
{
printf("%s Connection successn", pDatabaseName); //
MYSQL *m_pmySQL;
CDatabase_mySQL::CDatabase_mySQL()
{
m_pmySQL = NULL; //初始化
}
void CDatabase_mySQL::CloseDatabase(void)
{
if (m_pmySQL)
{
mysql_close(m_pmySQL);
m_pmySQL = NULL;
}
}
bool CDatabase_mySQL::OpenDatabase(char *pHostName, char *pDatabaseName, char *pUserName, char *pPwd)
{
CloseDatabase();
if ((m_pmySQL = mysql_init(NULL)) == NULL)
{
return false;
}
if (mysql_real_connect(m_pmySQL, "localhost", "root", "", "testdb", 0, NULL, 0))
{
printf("%s Connection successn", pDatabaseName); //