MySQL Connect
#1

Hey!

There's a mysql connect function under OnGameModeInit():

pawn Код:
if(mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS))
{
printf("\n[MySQL]: Succesful connect to database '%s'!\n", MYSQL_DB);
return 1;
}
printf("\n[MySQL]: [Error]: Cannot connect to database '%s'!\n", MYSQL_DB);
The problem is, when I run the gamemode without the mysql server running, it prints the 1st message, and using the functions (for example the registration) without it, so I can log in with any passwords.
How can I fix it to work correctly?

Thanks
Nonameman
Reply
#2

I didn't understand your problem. Why the hell you use mysql, if you start the game mode without it?
Reply
#3

Quote:
Originally Posted by wups
Посмотреть сообщение
I didn't understand your problem. Why the hell you use mysql, if you start the game mode without it?
He means that if he starts his server while his MySQL server is offline, it'll print that the connection was successful.

I have the same problem.
pawn Код:
if ( mysql_connect( ... ) )
{
    print( "Success" );
}
else
{
    print( "Failure" );
}
Failure is not being called even if the MySQL server is offline.
________
LovelyWendie
Reply
#4

Quote:
Originally Posted by [NoV]LaZ
Посмотреть сообщение
He means that if he starts his server while his MySQL server is offline, it'll print that the connection was successful.
In that case, its likely he is using G-StyleZzZ's plugin, which can not be used this way. The connect function returns a connection handle, not true or false if the db has connected. Use mysql_ping to see if the db is active.
Reply
#5

Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
In that case, its likely he is using G-StyleZzZ's plugin, which can not be used this way. The connect function returns a connection handle, not true or false if the db has connected. Use mysql_ping to see if the db is active.
I've used that method of checking the connection with Adrenaline's plugin, thanks for clarifying.
________
Ferrari F40 Specifications
Reply
#6

So:

pawn Код:
OnGameModeInit()
{
mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DB, MYSQL_PASS);
if(mysql_ping() == -1)
{
print("Failure");
}
else
{
print("Success");
}
return 1;
}
Is this good?
Reply
#7

Even the first version was good, put on mysql_debug(true); and see what it prints.
Reply
#8

i suggest that

pawn Код:
mysql_connect(blablabla....);

if(mysql_ping() != -1)
{
print("success!");
}
else
{
print("failed!");
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)