Database reconnect! - 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: Database reconnect! (
/showthread.php?tid=575624)
Database reconnect! -
bgedition - 28.05.2015
Hey all,
I wanna make when my mysql database colud not connect tor try again.
this is my code but when I am trying to connect to unknown database the server crashes.
Код:
//BG-Edition Test Gamemode by MichaelGoodman!
#include <a_samp>
#include <a_mysql>
#include <sscanf>
#include <zcmd>
#include <streamer>
#include <bgedition>
//- mysql connection
#define mysql_host "localhost"
#define mysql_user "root"
#define mysql_password "bg3diti0n"
#define mysql_database "bgedsitiontestsamp"
//- news
new mysql_handle[50], mysql_conatt = 5, bool:mysql_connected[50] = false;
main() {
}
public OnGameModeInit() {
mysql_conatt = 5;
mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
mysql_handle[0] = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
if(mysql_errno(mysql_handle[0]) == 0) {
print("[DEBUG]: Connected to the MySQL database!");
mysql_connected[0] = true;
} else {
mysql_conatt--;
mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
print("[DEBUG]: Could not connect to the MySQL database. Reconecting...");
if(mysql_conatt == 0) {
mysql_connected[0] = false;
//there i'm doing something
}
}
return 1;
}
public OnGameModeExit() {
mysql_close(mysql_handle[0]), mysql_connected = false;
return 1;
}
this is the output from crashdetect:
Код:
[28/05/2015 19:56:21] [debug] Server crashed while executing BulgEdition.amx
[28/05/2015 19:56:21] [debug] AMX backtrace:
[28/05/2015 19:56:21] [debug] #0 native mysql_connect () from mysql.DLL
[28/05/2015 19:56:21] [debug] #1 000069e8 in public zcmd_OnGameModeInit () from BulgEdition.amx
[28/05/2015 19:56:21] [debug] #2 native CallLocalFunction () from samp-server.exe
[28/05/2015 19:56:21] [debug] #3 00005d5c in public SSCANF_OnGameModeInit () from BulgEdition.amx
[28/05/2015 19:56:21] [debug] #4 00000104 in public OnGameModeInit () from BulgEdition.amx
[28/05/2015 19:56:22] [debug] Native backtrace:
[28/05/2015 19:56:22] [debug] #0 5c98a017 in ?? () from libmysql.dll
what i'm doing wrong
can anyone help me, please? +rep
Re: Database reconnect! -
Konstantinos - 28.05.2015
I've never tried to reconnect to it as I didn't have to so I'm not completely sure but I believe this is what you need:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_reconnect
Re: Database reconnect! -
bgedition - 28.05.2015
same...
Re: Database reconnect! -
sammp - 28.05.2015
mysql_handle[50] LOL WTF
try
mysql_handle = -1