diff options
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php | 20 | ||||
-rw-r--r-- | system/database/drivers/postgre/postgre_driver.php | 35 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 |
3 files changed, 44 insertions, 12 deletions
diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index 1300772c5..2eb0606b3 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -90,6 +90,26 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- /** + * Database connection + * + * @param bool $persistent + * @return object + */ + public function db_connect($persistent = FALSE) + { + $this->conn_id = parent::db_connect($persistent); + + if (is_object($this->conn_id) && ! empty($this->schema)) + { + $this->simple_query('SET search_path TO '.$this->schema.',public'); + } + + return $this->conn_id; + } + + // -------------------------------------------------------------------- + + /** * Insert ID * * @param string $name diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 2a78a5701..acad016b3 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -131,13 +131,32 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Non-persistent database connection + * Database connection * + * @param bool $persistent * @return resource */ - public function db_connect() + public function db_connect($persistent = FALSE) { - return @pg_connect($this->dsn); + if ($persistent === TRUE + && ($conn = @pg_pconnect($this->dsn)) + && pg_connection_status($conn) === PGSQL_CONNECTION_BAD + && pg_ping($conn) === FALSE + ) + { + return FALSE; + } + else + { + $conn = @pg_connect($this->dsn); + } + + if ($conn && ! empty($this->schema)) + { + $this->simple_query('SET search_path TO '.$this->schema.',public'); + } + + return $conn; } // -------------------------------------------------------------------- @@ -149,15 +168,7 @@ class CI_DB_postgre_driver extends CI_DB { */ public function db_pconnect() { - $conn = @pg_pconnect($this->dsn); - if ($conn && pg_connection_status($conn) === PGSQL_CONNECTION_BAD) - { - if (pg_ping($conn) === FALSE) - { - return FALSE; - } - } - return $conn; + return $this->db_connect(TRUE); } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 6570eb790..d7cfdd532 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -150,6 +150,7 @@ Release Date: Not Released - Added ``update_batch()`` support. - Removed ``limit()`` and ``order_by()`` support for *UPDATE* and *DELETE* queries as PostgreSQL does not support those features. - Added a work-around for dead persistent connections to be re-created after a database restart. + - Changed ``db_connect()`` to include the (new) **schema** value into Postgre's **search_path** session variable. - Improved support of the CUBRID driver, including: - Added DSN string support. - Added persistent connections support. |