joomla/joomla-platform — pull request #1018 by robschley (2012-03-21 23:29:32+00:00)
Title: Updated database drivers to attempt to reconnect from database servers that have been disconnected.

This fixes an issue where the database server gets disconnected from the PHP connection resource. This can happen in two situations that I am aware of:

* The database server is heavily loaded and drops a connection.
* The resource was copied into a forked process which happens when forking JDaemon. If the child process closes the connection or finishes execution, the parent resource will be disconnected.

To address these two issues, if a valid cursor is not returned when executing a query, the driver will check if the resource is still connected to the database. If the resource is disconnected, it will attempt to reconnect and execute the query again. If the reconnect fails or if the server still shows as connected, the normal exception will be thrown.

For PDO drivers, this required a better implementation of the connected() method. I attempted to use PDO::getAttribute(ATTR_CONNECTION_STATUS) but that feature is not supported on Sqlite or Oracle, possibly others. To work around that, the connected() method will attempt to execute a simple database query. To prevent contamination of the driver state, the previous query information is backed up and then restored after the query is executed.