If MySQL connection dies.
#1

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?
Reply
#2

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.
Reply
#3

https://sampwiki.blast.hk/wiki/MySQL/R33#OnQueryError
CR_SERVER_GONE_ERROR

No need for a timer.
Reply
#4

But I want as soon as the connection is dead to switch to another backup database.
Reply
#5

Bump.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply
#9

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
Reply
#10

@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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)