MySQLConnect()
#1

Hi,

Why isn't this working?

I turn my WAMP MySQL off to test it, but the text won't be printed and the server doesn't close.

Код:
stock MySQLConnect()
{
	mysql_debug(1);
	if(!mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
	{
		print("Server failed to connect to MySQL!");
		SendRconCommand("exit");
	}
	return 0;
}
Reply
#2

Because "mysql_connect" returns the connection handle instead of 'fail' or 'success'

Instead you could do:

pawn Код:
if(mysql_ping()==-1)
{
    print("Server failed to connect to MySQL!");
    SendRconCommand("exit");
}
Reply
#3

Thanks for answering!

Like this?

Код:
stock MySQLConnect()
{
	mysql_debug(1);
	if(!mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS))
	{
		if(mysql_ping()==-1)
		{
			print("Server failed to connect to MySQL!");
			SendRconCommand("exit");
		}
	}	
	return 0;
}
It doesn't work
Reply
#4

pawn Код:
stock MySQLConnect()
{
    mysql_debug(1);
    mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);

    if (mysql_ping()) == -1)
    {
        print("Server failed to connect to MySQL!");
        SendRconCommand("exit");
    }
    else
    {
        print("Connection successful\nGood day");
    }
}
Reply
#5

It works, thanks man!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)