If MySQL connection dies. - 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: If MySQL connection dies. (
/showthread.php?tid=615291)
If MySQL connection dies. -
bgedition - 20.08.2016
Hello there, I have a question for you.
How can I detect when a MySQL connection dies during server run time? Is it possible or not?
Re: If MySQL connection dies. -
oMa37 - 20.08.2016
I think so?
Try this, set a timer that repeats every 1 minute and use mysql_errno().
Haven't tried it yet, But it may work.
Re: If MySQL connection dies. -
Stinged - 20.08.2016
https://sampwiki.blast.hk/wiki/MySQL/R33#OnQueryError
CR_SERVER_GONE_ERROR
No need for a timer.
Re: If MySQL connection dies. -
bgedition - 20.08.2016
But I want as soon as the connection is dead to switch to another backup database.
Re: If MySQL connection dies. -
bgedition - 22.08.2016
Bump.
Re: If MySQL connection dies. -
PrO.GameR - 22.08.2016
You can use mysql callback OnQueryError + mysql_ping to see if it's connected, if it's not then either reconnect it, or resend the query to your backup database.
Re: If MySQL connection dies. -
bgedition - 22.08.2016
Yeah but the problem is I'am using the latest version of BlueG's mysql plugin and the callback mysql_ping does not exist anymore.
Re: If MySQL connection dies. -
Konstantinos - 22.08.2016
Quote:
Originally Posted by bgedition
Yeah but the problem is I'am using the latest version of BlueG's mysql plugin and the callback mysql_ping does not exist anymore.
|
Go to the link Stinged provided, it shows exactly how to detect if the connection to mysql server was lost.
Re: If MySQL connection dies. - iLearner - 22.08.2016
There's a parameter in mysql_connect, that, if set to 1(true) will reconnect automatically once lost connection.
Ping thing was removed cuz of this parameter
Re: If MySQL connection dies. -
bgedition - 22.08.2016
@Kostantinos My idea was as soon as the connection dies to connect to a different database. With the callback OnQueryError, the server would have to send a query every second to check the connection status.