void connect_db()
{
char output[MAX_STRING_LENGTH];
MYSQL mysql;
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"biyg");
if (!mysql_real_connect(&mysql,"localhost","root","pass","mydb",0,NULL,0))
{
sprintf(output, "Failed to connect to database: Error: %s\n", mysql_error(&mysql));
log_string(output);
}
}
void init_mysql( )
{
if( !mysql_init( &myconn ) )
{
mysql_close( &myconn );
bug( "%s: mysql_init() failed.", __FUNCTION__ );
log_printf( "Error: %s.", mysql_error( &myconn ) );
return;
}
if( !mysql_real_connect( &myconn, sysdata->dbserver.c_str( ), sysdata->dbuser.c_str( ), sysdata->dbpass.c_str( ), sysdata->dbname.c_str( ), 0, NULL, 0 ) )
{
mysql_close( &myconn );
bug( "%s: mysql_real_connect() failed.", __FUNCTION__ );
log_printf( "Error: %s.", mysql_error( &myconn ) );
return;
}
mysql_options( &myconn, MYSQL_OPT_RECONNECT, "1" );
log_string( "Connection to mysql database established." );
}
It works:
And in my MUD, I have this:
It fails:
Note the constants (DB_USER, etc) are all defined and correct, and the same in both files.
Why is the MUD connection failing? What else could prevent it? I've even tried hard coding the username into into mysql_real_connect().