[英]Can't connect to mysql server with mysql_real_connect()
I can't connect to MySQL remote server with this code: 我无法使用以下代码连接到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;
}
after running this code there is a message in the console: 运行此代码后,控制台中将显示一条消息:
connection failure
连接失败
At the first line of your code MYSQL conn
. 在代码
MYSQL conn
的第一行。 This is the prototype for mysql_real_connect: 这是mysql_real_connect的原型:
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
should be a pointer. conn
应该是一个指针。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.