我无法使用以下代码连接到 MySQL 远程服务器:
MYSQL conn;
bool con_to_db()
{
conn = mysql_init(0);
conn =mysql_real_connect(conn, host, user, pass, 0, NULL, 0);
if(conn)
//cout<<"connection to atestat databse successful "<<endl;
return true;
else
// cout<<"connection problem: "<<mysql_error(conn)<<endl;
return false;
}
int main()
{
if(con_to_db())
cout<<"connection to atestat databse successful "<<endl;
else
cout<<"connection problem: "<<mysql_error(conn)<<endl;
}
运行此代码后,控制台中会显示一条消息:
connection failure
最佳答案
在代码的第一行MYSQL conn
。这是 mysql_real_connect 的原型(prototype):
MYSQL * mysql_real_connect(MYSQL * mysql,
const char * host,
const char * user,
const char * passwd,
const char * db,
unsigned int port,
const char * unix_socket,
unsigned long flags);
conn
应该是一个指针。
关于c++ - 无法使用 mysql_real_connect() 连接到 mysql 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55634760/