MySQL Connect - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Connect (
/showthread.php?tid=169888)
MySQL Connect -
Nonameman - 21.08.2010
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
Re: MySQL Connect -
wups - 21.08.2010
I didn't understand your problem. Why the hell you use mysql, if you start the game mode without it?
MySQL Connect -
[NoV]LaZ - 21.08.2010
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
Re: MySQL Connect -
Kyosaur - 21.08.2010
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.
MySQL Connect -
[NoV]LaZ - 21.08.2010
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
Re: MySQL Connect -
Nonameman - 21.08.2010
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?
Re: MySQL Connect - WackoX - 21.08.2010
Even the first version was good, put on mysql_debug(true); and see what it prints.
Re: MySQL Connect -
Kirollos - 19.04.2012
i suggest that
pawn Код:
mysql_connect(blablabla....);
if(mysql_ping() != -1)
{
print("success!");
}
else
{
print("failed!");
}