diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-12-03 13:55:56 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-12-03 13:55:56 +0100 |
commit | 0259d1240d298beb71627da9c808c2f6a41e4656 (patch) | |
tree | fcef85bc679b1d7aca67ed0c30c521034cc5757b /system/database/drivers/postgre | |
parent | 838a9d69a9139b6bcd6f8765fdd2d58b929e70ad (diff) |
Improve schema support for Postgre
Diffstat (limited to 'system/database/drivers/postgre')
-rw-r--r-- | system/database/drivers/postgre/postgre_driver.php | 35 |
1 files changed, 23 insertions, 12 deletions
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); } // -------------------------------------------------------------------- |