[Devel] mysql module failed to reconnect after mysql restart

Dan Pascu dan at ag-projects.com
Fri Jan 13 22:32:33 CET 2006


On Friday 13 January 2006 21:18, Norman Brandinger wrote:
> Hi Daniel / Raymond
>
> Note that upon connection, mysql_real_connect() sets the reconnect flag
> (part of the MYSQL structure) to a value of 1 in versions of the API
> older than 5.0.3, or 0 in newer versions. A value of 1 for this flag
> indicates that if a statement cannot be performed because of a lost
> connection, to try reconnecting to the server before giving up. As of
> MySQL 5.0.13, you can use the MYSQL_OPT_RECONNECT option to
> mysql_options() to control reconnection behavior.
>
> I have tested the following code (note that only the important pieces
> are listed below) and my application was able to automatically
> reconnect to MySQL.  The example below uses BOTH the
> "MYSQL_OPT_RECONNECT" and the "conn->reconnect = 1" forms to set the
> reconnect flag.  As memory serves, "MYSQL_OPT_RECONNECT" didn't work
> for me.

Even though the documentation says that you should call mysql_options 
before mysql_real_connect, when setting MYSQL_OPT_RECONNECT you MUST do 
so after the connection has been successfully established.

This is true as late as 5.0.16.

anyway setting conn->reconnect = 1 seems much simpler and less tricky. 
with MYSQL_OPT_RECONNECT, you have to actually make sure you have that 
symbol defined, as it was only introduced in 5.0.13 and the code needs to 
work with all versions of the mysql client lib.

-- 
Dan



More information about the Devel mailing list