Problem connecting to mysql server. - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem connecting to mysql server. (
/showthread.php?tid=182983)
Problem connecting to mysql server. -
Dj_maryo1993 - 13.10.2010
Function :
pawn Code:
public MySQLConnect(sqlhost[], sqluser[],database[], sqlpass[])
{
print("MYSQL: Attempting to connect to server...");
mysql_connect(sqlhost, sqluser,database, sqlpass);
if(mysql_ping()==0)
{
print("MYSQL: Database connection established.");
return 1;
}
else
{
print("MYSQL: Connection error, retrying...");
mysql_reconnect();
if(mysql_ping()==0)
{
print("MYSQL: Reconnection successful. We can continue as normal.");
return 1;
}
else
{
print("MYSQL: Could not reconnect to server, terminating server...");
SendRconCommand("exit");
return 0;
}
}
}
Called with :
pawn Code:
MySQLConnect(MYSQL_HOST,MYSQL_USER,MYSQL_DB,MYSQL_PASS);
Gives me :
Code:
----------
Loaded log file: "server_log.txt".
----------
SA-MP Dedicated Server
----------------------
v0.3b R2, ©2005-2010 SA-MP Team
[06:24:17] filterscripts = "" (string)
[06:24:17]
[06:24:17] Server Plugins
[06:24:17] --------------
[06:24:17] Loading plugin: mysql
[06:24:17]
> MySQL plugin R5 successfully loaded.
[06:24:17] Loaded.
[06:24:17] Loaded 1 plugins.
[06:24:17]
[06:24:17] Filter Scripts
[06:24:17] ---------------
[06:24:17] Loaded 0 filter scripts.
[06:24:17]
----------------------------------
[06:24:17] v0
[06:24:17] ----------------------------------
[06:24:17] MYSQL: Attempting to connect to server...
[06:24:18] MYSQL: Connection error, retrying...
[06:24:18] MYSQL: Could not reconnect to server, terminating server...
[06:24:18] Number of vehicle models: 0
[06:24:18] --- Server Shutting Down.
[06:24:18]
> MySQL plugin unloaded.
LE : I double checked the mysql db , the db works ok.
Re: Problem connecting to mysql server. -
Dj_maryo1993 - 13.10.2010
It seems that the error is in checking if the sql connection is ok or not , plese someone give me a proper way to test my sql connection .