verification 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: verification mysql connect (
/showthread.php?tid=542577)
verification mysql connect -
Sielly - 20.10.2014
Hello,
how can I verification if my script is connected to mysql?
I am using this mysql_connect(host,user,dbas,pass), but I don't know does it connected.
Thanks.
Re: verification mysql connect -
zaibaslr2 - 20.10.2014
Код:
if(mysql_ping())
{
...//connected
}
if(!mysql_ping())
{
...//not connected
}
Re: verification mysql connect -
Sielly - 20.10.2014
undefined symbol "mysql_ping"
I'm using this:
https://sampforum.blast.hk/showthread.php?tid=56564
Re: verification mysql connect -
iZN - 20.10.2014
pawn Код:
// after mysql_connect
if(mysql_errno() != 0)
{
print(!"[ERROR] Connection to MySQL failed.");
SendRconCommand("exit"); // remove this if you don't want your server to be closed.
return false;
}
Re: verification mysql connect -
zaibaslr2 - 20.10.2014
At the top:
new mysql;
Where you connect to database
mysql = mysql_connect(......);
if(mysql_ping(mysql))
{
...//got connection
}
else
{
..//didn't connect
}
Re: verification mysql connect -
Sielly - 20.10.2014
instead of if(mysql_errno() != 0) should be if(mysql_errno() == 0)
it works, thanks for help! rep+
Re: verification mysql connect -
DanishHaq - 20.10.2014
You need to put it under OnGameModeInit:
pawn Код:
public OnGameModeInit()
{
mysql_connect(/*.....................*/);
if(mysql_ping() == 0) printf("failed to connect to db");
else printf("connected to db");
return 1;
}
Wups I replied too late
Re: verification mysql connect -
Sielly - 20.10.2014
Danish i know, and i put it into ongamemodeinit, but i don't have mysql_ping function I don't know why, but mysql_errno works.