diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-03-26 20:51:00 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-03-26 20:51:00 +0200 |
commit | 925d37391789405f53da73979305dead6a053099 (patch) | |
tree | 0ed90207fe66bb5491e8925d20d48c211a897cf8 /system/database/drivers/postgre/postgre_driver.php | |
parent | e6f7d610b189e243ad48dcc3900a5c53cab2498d (diff) | |
parent | 84c3b27fface58ecfcd0acf7172d3ee2043b3673 (diff) |
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop-helpers-acc
Diffstat (limited to 'system/database/drivers/postgre/postgre_driver.php')
-rw-r--r-- | system/database/drivers/postgre/postgre_driver.php | 89 |
1 files changed, 54 insertions, 35 deletions
diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8112cf9de..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 !== '') + { + $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) && $this->$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); } // -------------------------------------------------------------------- @@ -189,28 +224,12 @@ class CI_DB_postgre_driver extends CI_DB { */ protected function _execute($sql) { - $sql = $this->_prep_query($sql); return @pg_query($this->conn_id, $sql); } // -------------------------------------------------------------------- /** - * Prep the query - * - * If needed, each database adapter can prep the query string - * - * @param string an SQL query - * @return string - */ - protected function _prep_query($sql) - { - return $sql; - } - - // -------------------------------------------------------------------- - - /** * Begin Transaction * * @return bool @@ -659,4 +678,4 @@ class CI_DB_postgre_driver extends CI_DB { } /* End of file postgre_driver.php */ -/* Location: ./system/database/drivers/postgre/postgre_driver.php */ +/* Location: ./system/database/drivers/postgre/postgre_driver.php */
\ No newline at end of file |