Posts: 417
Threads: 40
Joined: Oct 2013
Reputation:
0
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?
Posts: 928
Threads: 13
Joined: Feb 2016
Reputation:
0
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.
Posts: 417
Threads: 40
Joined: Oct 2013
Reputation:
0
But I want as soon as the connection is dead to switch to another backup database.
Posts: 694
Threads: 2
Joined: Oct 2012
Reputation:
0
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.
Posts: 417
Threads: 40
Joined: Oct 2013
Reputation:
0
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.
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
Posts: 417
Threads: 40
Joined: Oct 2013
Reputation:
0
@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.