From 2e171023bae38735ec08bbd9cb160cee75edbc62 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 25 Feb 2014 15:21:41 +0200 Subject: Make db_pconnect an alias for db_connect(TRUE) and reduce code repetition --- system/database/drivers/cubrid/cubrid_driver.php | 56 ++++------------------ system/database/drivers/ibase/ibase_driver.php | 19 ++------ system/database/drivers/mssql/mssql_driver.php | 12 ----- system/database/drivers/mysql/mysql_driver.php | 12 ----- system/database/drivers/mysqli/mysqli_driver.php | 12 ----- system/database/drivers/oci8/oci8_driver.php | 22 ++------- system/database/drivers/odbc/odbc_driver.php | 19 ++------ system/database/drivers/pdo/pdo_driver.php | 12 ----- system/database/drivers/postgre/postgre_driver.php | 12 ----- system/database/drivers/sqlite/sqlite_driver.php | 42 +++------------- system/database/drivers/sqlite3/sqlite3_driver.php | 23 ++++----- system/database/drivers/sqlsrv/sqlsrv_driver.php | 12 ----- 12 files changed, 39 insertions(+), 214 deletions(-) (limited to 'system/database/drivers') diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 0db51735c..2e79faa39 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -102,61 +102,23 @@ class CI_DB_cubrid_driver extends CI_DB { /** * Non-persistent database connection * - * @return resource - */ - public function db_connect() - { - return $this->_cubrid_connect(); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * In CUBRID persistent DB connection is supported natively in CUBRID - * engine which can be configured in the CUBRID Broker configuration - * file by setting the CCI_PCONNECT parameter to ON. In that case, all - * connections established between the client application and the - * server will become persistent. - * - * @return resource - */ - public function db_pconnect() - { - return $this->_cubrid_connect(TRUE); - } - - // -------------------------------------------------------------------- - - /** - * CUBRID connection - * - * A CUBRID-specific method to create a connection to the database. - * Except for determining if a persistent connection should be used, - * the rest of the logic is the same for db_connect() and db_pconnect(). - * * @param bool $persistent * @return resource */ - protected function _cubrid_connect($persistent = FALSE) + public function db_connect($persistent = FALSE) { if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches)) { - $_temp = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; - $conn_id = ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') - ? $_temp($this->dsn, $this->username, $this->password) - : $_temp($this->dsn); - } - else - { - $_temp = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; - $conn_id = ($this->username !== '') - ? $_temp($this->hostname, $this->port, $this->database, $this->username, $this->password) - : $_temp($this->hostname, $this->port, $this->database); + $func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url'; + return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '') + ? $func($this->dsn, $this->username, $this->password) + : $func($this->dsn); } - return $conn_id; + $func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect'; + return ($this->username !== '') + ? $func($this->hostname, $this->port, $this->database, $this->username, $this->password) + : $func($this->hostname, $this->port, $this->database); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index 4cff5f448..c85b19955 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -69,23 +69,14 @@ class CI_DB_ibase_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool $persistent * @return resource */ - public function db_connect() + public function db_connect($persistent = FALSE) { - return @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - return @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); + return ($persistent === TRUE) + ? @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set) + : @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 9e53d4e6d..075542ae0 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -129,18 +129,6 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - return $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - /** * Select the database * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 499d42691..9fbd94ce8 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -145,18 +145,6 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - return $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - /** * Reconnect * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 083b0c621..b2d0bcc87 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -113,18 +113,6 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return object - */ - public function db_pconnect() - { - return $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - /** * Reconnect * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index f309a8272..7453db7a8 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -208,27 +208,15 @@ class CI_DB_oci8_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool $persistent * @return resource */ - public function db_connect() - { - return ( ! empty($this->char_set)) - ? @oci_connect($this->username, $this->password, $this->dsn, $this->char_set) - : @oci_connect($this->username, $this->password, $this->dsn); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() + public function db_connect($persistent = FALSE) { + $func = ($persistent === TRUE) ? 'oci_pconnect' : 'oci_connect'; return empty($this->char_set) - ? @oci_pconnect($this->username, $this->password, $this->dsn) - : @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set); + ? $func($this->username, $this->password, $this->dsn) + : $func($this->username, $this->password, $this->dsn, $this->char_set); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 662a1063a..14c85c8e2 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -104,23 +104,14 @@ class CI_DB_odbc_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool $persistent * @return resource */ - public function db_connect() + public function db_connect($persistent = FALSE) { - return @odbc_connect($this->dsn, $this->username, $this->password); - } - - // -------------------------------------------------------------------- - - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - return @odbc_pconnect($this->dsn, $this->username, $this->password); + return ($persistent === TRUE) + ? odbc_pconnect($this->dsn, $this->username, $this->password) + : odbc_connect($this->dsn, $this->username, $this->password); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 49612b972..01731489f 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -134,18 +134,6 @@ class CI_DB_pdo_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return object - */ - public function db_pconnect() - { - return $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - /** * Database version number * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 7d17f799e..1140d501b 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -161,18 +161,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - return $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - /** * Reconnect * diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 9928aedb7..dd9e1e849 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -62,45 +62,17 @@ class CI_DB_sqlite_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool $persistent * @return resource */ - public function db_connect() + public function db_connect($persistent = FALSE) { - if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } - - return $conn_id; - } - - // -------------------------------------------------------------------- + $error = NULL; + $conn_id = ($persistent === TRUE) + ? sqlite_popen($this->database, 0666, $error) + : sqlite_open($this->database, 0666, $error); - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error)) - { - log_message('error', $error); - - if ($this->db_debug) - { - $this->display_error($error, '', TRUE); - } - - return FALSE; - } + isset($error) && log_message('error', $error); return $conn_id; } diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 30c38ec47..a7d0d087d 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -63,10 +63,16 @@ class CI_DB_sqlite3_driver extends CI_DB { /** * Non-persistent database connection * - * @return object type SQLite3 + * @param bool $persistent + * @return SQLite3 */ - public function db_connect() + public function db_connect($persistent = FALSE) { + if ($persistent) + { + log_message('debug', 'SQLite3 doesn\'t support persistent connections'); + } + try { return ( ! $this->password) @@ -81,19 +87,6 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return object type SQLite3 - */ - public function db_pconnect() - { - log_message('debug', 'SQLite3 doesn\'t support persistent connections'); - return $this->db_connect(); - } - - // -------------------------------------------------------------------- - /** * Database version number * diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index a723b78bc..58f2e3420 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -143,18 +143,6 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * Persistent database connection - * - * @return resource - */ - public function db_pconnect() - { - return $this->db_connect(TRUE); - } - - // -------------------------------------------------------------------- - /** * Select the database * -- cgit v1.2.3-24-g4f1b