summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/postgre/postgre_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-28 12:46:47 +0200
committerAndrey Andreev <narf@bofh.bg>2012-03-28 12:46:47 +0200
commit11c111c3ff128791f571ac2519bb796baecf7226 (patch)
tree4ac0873487f29f9f548edc8ddd5c26b065b5910b /system/database/drivers/postgre/postgre_driver.php
parentc082292f0678b71b8c3d323ea74f847ed4da100e (diff)
parent3b2587e1559d2cbe751d04f801f999ef3fa4e74c (diff)
Merge upstream branch
Diffstat (limited to 'system/database/drivers/postgre/postgre_driver.php')
-rw-r--r--system/database/drivers/postgre/postgre_driver.php71
1 files changed, 53 insertions, 18 deletions
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php
index 3bfccad05..3e2d05ce8 100644
--- a/system/database/drivers/postgre/postgre_driver.php
+++ b/system/database/drivers/postgre/postgre_driver.php
@@ -57,29 +57,64 @@ class CI_DB_postgre_driver extends CI_DB {
protected $_random_keyword = ' RANDOM()'; // database specific random keyword
/**
- * Connection String
+ * Constructor
*
- * @return string
+ * Creates a DSN string to be used for db_connect() and db_pconnect()
+ *
+ * @return void
*/
- protected function _connect_string()
+ public function __construct($params)
{
- $components = array(
- 'hostname' => 'host',
- 'port' => 'port',
- 'database' => 'dbname',
- 'username' => 'user',
- 'password' => 'password'
- );
-
- $connect_string = "";
- foreach ($components as $key => $val)
+ parent::__construct($params);
+
+ if ( ! empty($this->dsn))
+ {
+ return;
+ }
+
+ $this->dsn === '' OR $this->dsn = '';
+
+ if (strpos($this->hostname, '/') !== FALSE)
+ {
+ // If UNIX sockets are used, we shouldn't set a port
+ $this->port = '';
+ }
+
+ $this->hostname === '' OR $this->dsn = 'host='.$this->hostname;
+
+ if ( ! empty($this->port) && ctype_digit($this->port))
+ {
+ $this->dsn .= 'host='.$this->port.' ';
+ }
+
+ if ($this->username !== '')
{
- if (isset($this->$key) && $this->$key != '')
+ $this->dsn .= 'username='.$this->username.' ';
+
+ /* An empty password is valid!
+ *
+ * $db['password'] = NULL must be done in order to ignore it.
+ */
+ $this->password === NULL OR $this->dsn .= "password='".$this->password."' ";
+ }
+
+ $this->database === '' OR $this->dsn .= 'dbname='.$this->database.' ';
+
+ /* We don't have these options as elements in our standard configuration
+ * array, but they might be set by parse_url() if the configuration was
+ * provided via string. Example:
+ *
+ * postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
+ */
+ foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
+ {
+ if (isset($this->$key) && is_string($this->key) && $this->key !== '')
{
- $connect_string .= " $val=".$this->$key;
+ $this->dsn .= $key."='".$this->key."' ";
}
}
- return trim($connect_string);
+
+ $this->dsn = rtrim($this->dsn);
}
// --------------------------------------------------------------------
@@ -91,7 +126,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_connect()
{
- return @pg_connect($this->_connect_string());
+ return @pg_connect($this->dsn);
}
// --------------------------------------------------------------------
@@ -103,7 +138,7 @@ class CI_DB_postgre_driver extends CI_DB {
*/
public function db_pconnect()
{
- return @pg_pconnect($this->_connect_string());
+ return @pg_pconnect($this->dsn);
}
// --------------------------------------------------------------------