From 87cbafce2d6803af78714baf8bba64309c01fc33 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Feb 2009 16:29:59 +0000 Subject: added reconnect() method to db drivers --- system/database/drivers/mssql/mssql_driver.php | 16 ++++++++++++++++ system/database/drivers/mysql/mysql_driver.php | 19 +++++++++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 19 +++++++++++++++++++ system/database/drivers/oci8/oci8_driver.php | 16 ++++++++++++++++ system/database/drivers/odbc/odbc_driver.php | 16 ++++++++++++++++ system/database/drivers/postgre/postgre_driver.php | 19 +++++++++++++++++++ system/database/drivers/sqlite/sqlite_driver.php | 16 ++++++++++++++++ user_guide/changelog.html | 1 + user_guide/database/connecting.html | 5 +++++ 9 files changed, 127 insertions(+) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index ddc036da9..241b280d0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -82,7 +82,23 @@ class CI_DB_mssql_driver extends CI_DB { } // -------------------------------------------------------------------- + + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in MSSQL + } + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 2b05c3f15..334daf3a6 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -90,6 +90,25 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (mysql_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 6558112cd..74cfff44a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -90,6 +90,25 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (mysqli_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 4dfec2e3f..f4ef42a18 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -97,6 +97,22 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in oracle + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index f7db4ca4b..2e529f32d 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -81,6 +81,22 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in odbc + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 4bc5b7d94..db3a3f29d 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -101,6 +101,25 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + if (pg_ping($this->conn_id) === FALSE) + { + $this->conn_id = FALSE; + } + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index bb1e6d02e..cd7b26bc4 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -99,6 +99,22 @@ class CI_DB_sqlite_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Reconnect + * + * Keep / reestablish the db connection if no queries have been + * sent for a length of time exceeding the server's idle timeout + * + * @access public + * @return void + */ + function reconnect() + { + // not implemented in SQLite + } + + // -------------------------------------------------------------------- + /** * Select the database * diff --git a/user_guide/changelog.html b/user_guide/changelog.html index cdbfbbd04..3ddaf8d08 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -74,6 +74,7 @@ SVN Revision:

  • Updated all database drivers to handle arrays in escape_str()
  • Added escape_like_str() method for escaping strings to be used in LIKE conditions
  • Updated Active Record to utilize the new LIKE escaping mechanism.
  • +
  • Added reconnect() method to DB drivers to try to keep alive / reestablish a connection after a long idle.
  • diff --git a/user_guide/database/connecting.html b/user_guide/database/connecting.html index 3579e1af6..b4d517941 100644 --- a/user_guide/database/connecting.html +++ b/user_guide/database/connecting.html @@ -158,6 +158,11 @@ you can pass the connection values as indicated above).

    +

    Reconnecting / Keeping the Connection Alive

    + +

    If the database server's idle timeout is exceeded while you're doing some heavy PHP lifting (processing an image, for instance), you should consider pinging the server by using the reconnect() method before sending further queries, which can gracefully keep the connection alive or re-establish it.

    + +$this->db->reconnect(); -- cgit v1.2.3-24-g4f1b