summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-26 21:08:49 +0200
committerAndrey Andreev <narf@bofh.bg>2012-03-26 21:08:49 +0200
commit1a361209cf77133d2a38132cebe1db17df04a7d4 (patch)
tree9132215eecd4fae44e6dd3e24f5928b8a5d3cad9 /system/database
parent7fd46308949522f1c7c8853381c2ce7cea093c9a (diff)
parent5bc7a2393187a25f832f18552dbdb8defb23e9d1 (diff)
Merge upstream branch
Diffstat (limited to 'system/database')
-rwxr-xr-xsystem/database/DB.php24
-rw-r--r--system/database/DB_active_rec.php40
-rw-r--r--system/database/DB_driver.php17
-rw-r--r--system/database/drivers/cubrid/cubrid_driver.php85
-rw-r--r--system/database/drivers/interbase/interbase_driver.php15
-rw-r--r--system/database/drivers/mssql/mssql_driver.php18
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php1
-rw-r--r--system/database/drivers/oci8/oci8_driver.php103
-rw-r--r--system/database/drivers/odbc/odbc_driver.php26
-rw-r--r--system/database/drivers/pdo/pdo_driver.php22
-rw-r--r--system/database/drivers/postgre/postgre_driver.php71
-rw-r--r--system/database/drivers/postgre/postgre_utility.php2
-rw-r--r--system/database/drivers/sqlite/sqlite_driver.php21
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php15
14 files changed, 252 insertions, 208 deletions
diff --git a/system/database/DB.php b/system/database/DB.php
index 116116bf4..96e495515 100755
--- a/system/database/DB.php
+++ b/system/database/DB.php
@@ -37,11 +37,11 @@
function &DB($params = '', $active_record_override = NULL)
{
// Load the DB config file if a DSN string wasn't passed
- if (is_string($params) AND strpos($params, '://') === FALSE)
+ if (is_string($params) && strpos($params, '://') === FALSE)
{
// Is the config file in the environment folder?
if (( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
- AND ! file_exists($file_path = APPPATH.'config/database.php'))
+ && ! file_exists($file_path = APPPATH.'config/database.php'))
{
show_error('The configuration file database.php does not exist.');
}
@@ -74,24 +74,24 @@ function &DB($params = '', $active_record_override = NULL)
* parameter. DSNs must have this prototype:
* $dsn = 'driver://username:password@hostname/database';
*/
- if (($dns = @parse_url($params)) === FALSE)
+ if (($dsn = @parse_url($params)) === FALSE)
{
show_error('Invalid DB Connection String');
}
$params = array(
- 'dbdriver' => $dns['scheme'],
- 'hostname' => (isset($dns['host'])) ? rawurldecode($dns['host']) : '',
- 'port' => (isset($dns['port'])) ? rawurldecode($dns['port']) : '',
- 'username' => (isset($dns['user'])) ? rawurldecode($dns['user']) : '',
- 'password' => (isset($dns['pass'])) ? rawurldecode($dns['pass']) : '',
- 'database' => (isset($dns['path'])) ? rawurldecode(substr($dns['path'], 1)) : ''
+ 'dbdriver' => $dsn['scheme'],
+ 'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '',
+ 'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '',
+ 'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '',
+ 'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '',
+ 'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
);
// were additional config items set?
- if (isset($dns['query']))
+ if (isset($dsn['query']))
{
- parse_str($dns['query'], $extra);
+ parse_str($dsn['query'], $extra);
foreach ($extra as $key => $val)
{
// booleans please
@@ -158,4 +158,4 @@ function &DB($params = '', $active_record_override = NULL)
}
/* End of file DB.php */
-/* Location: ./system/database/DB.php */
+/* Location: ./system/database/DB.php */ \ No newline at end of file
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index fe591dda1..b324226ab 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* Active Record Class
*
@@ -422,7 +420,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
foreach ($key as $k => $v)
{
- $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
+ $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type;
if (is_null($v) && ! $this->_has_operator($k))
{
@@ -537,7 +535,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* @param string The field to search
* @param array The values searched on
- * @param boolean If the statement would be IN or NOT IN
+ * @param bool If the statement would be IN or NOT IN
* @param string
* @return object
*/
@@ -719,7 +717,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
{
$type = $this->_group_get_type($type);
$this->ar_where_group_started = TRUE;
- $prefix = (count($this->ar_where) === 0 AND count($this->ar_cache_where) === 0) ? '' : $type;
+ $prefix = (count($this->ar_where) === 0 && count($this->ar_cache_where) === 0) ? '' : $type;
$this->ar_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->ar_where_group_count).' (';
if ($this->ar_caching)
@@ -984,8 +982,8 @@ abstract class CI_DB_active_record extends CI_DB_driver {
/**
* Sets the LIMIT value
*
- * @param integer the limit value
- * @param integer the offset value
+ * @param int the limit value
+ * @param int the offset value
* @return object
*/
public function limit($value, $offset = NULL)
@@ -1005,7 +1003,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
/**
* Sets the OFFSET value
*
- * @param integer the offset value
+ * @param int the offset value
* @return object
*/
public function offset($offset)
@@ -1021,7 +1019,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* @param mixed
* @param string
- * @param boolean
+ * @param bool
* @return object
*/
public function set($key, $value = '', $escape = TRUE)
@@ -1055,9 +1053,8 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* Compiles a SELECT query string and returns the sql.
*
- * @access public
* @param string the table name to select from (optional)
- * @param boolean TRUE: resets AR values; FALSE: leave AR vaules alone
+ * @param bool TRUE: resets AR values; FALSE: leave AR vaules alone
* @return string
*/
public function get_compiled_select($table = '', $reset = TRUE)
@@ -1226,7 +1223,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* @param mixed
* @param string
- * @param boolean
+ * @param bool
* @return object
*/
public function set_insert_batch($key, $value = '', $escape = TRUE)
@@ -1283,9 +1280,8 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an insert query and returns the sql
*
- * @access public
* @param string the table to insert into
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @param bool TRUE: reset AR values; FALSE: leave AR values alone
* @return string
*/
public function get_compiled_insert($table = '', $reset = TRUE)
@@ -1316,7 +1312,6 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an insert string and runs the query
*
- * @access public
* @param string the table to insert data into
* @param array an associative array of insert values
* @return object
@@ -1352,7 +1347,6 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* validate that the there data is actually being set and that table
* has been chosen to be inserted into.
*
- * @access public
* @param string the table to insert data into
* @return string
*/
@@ -1423,9 +1417,8 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* Compiles an update query and returns the sql
*
- * @access public
* @param string the table to update
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @param bool TRUE: reset AR values; FALSE: leave AR values alone
* @return string
*/
public function get_compiled_update($table = '', $reset = TRUE)
@@ -1499,7 +1492,6 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* validate that data is actually being set and that a table has been
* chosen to be update.
*
- * @access public
* @param string the table to update data on
* @return bool
*/
@@ -1584,7 +1576,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* @param array
* @param string
- * @param boolean
+ * @param bool
* @return object
*/
public function set_update_batch($key, $index = '', $escape = TRUE)
@@ -1696,9 +1688,8 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* Compiles a delete query string and returns the sql
*
- * @access public
* @param string the table to delete from
- * @param boolean TRUE: reset AR values; FALSE: leave AR values alone
+ * @param bool TRUE: reset AR values; FALSE: leave AR values alone
* @return string
*/
public function get_compiled_delete($table = '', $reset = TRUE)
@@ -1719,7 +1710,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
* @param mixed the table(s) to delete from. String or array
* @param mixed the where clause
* @param mixed the limit clause
- * @param boolean
+ * @param bool
* @return object
*/
public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE)
@@ -2062,7 +2053,6 @@ abstract class CI_DB_active_record extends CI_DB_driver {
*
* Empties the AR cache
*
- * @access public
* @return void
*/
public function flush_cache()
@@ -2114,7 +2104,7 @@ abstract class CI_DB_active_record extends CI_DB_driver {
// If we are "protecting identifiers" we need to examine the "from"
// portion of the query to determine if there are any aliases
- if ($this->_protect_identifiers === TRUE AND count($this->ar_cache_from) > 0)
+ if ($this->_protect_identifiers === TRUE && count($this->ar_cache_from) > 0)
{
$this->_track_aliases($this->ar_from);
}
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 42b1b35aa..9f1a0b895 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -171,6 +171,23 @@ abstract class CI_DB_driver {
// --------------------------------------------------------------------
/**
+ * Reconnect
+ *
+ * Keep / reestablish the db connection if no queries have been
+ * sent for a length of time exceeding the server's idle timeout.
+ *
+ * This is just a dummy method to allow drivers without such
+ * functionality to not declare it, while others will override it.
+ *
+ * @return void
+ */
+ public function reconnect()
+ {
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Set client character set
*
* @param string
diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php
index f39c2ad76..bed3d8685 100644
--- a/system/database/drivers/cubrid/cubrid_driver.php
+++ b/system/database/drivers/cubrid/cubrid_driver.php
@@ -57,38 +57,35 @@ class CI_DB_cubrid_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' RAND()'; // database specific random keyword
- /**
- * Non-persistent database connection
- *
- * @return resource
- */
- public function db_connect()
- {
- // If no port is defined by the user, use the default value
- if ($this->port == '')
- {
- // Default CUBRID Broker port
- $this->port = 33000;
- }
+ // CUBRID-specific properties
+ public $auto_commit = TRUE;
- $conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
+ public function __construct($params)
+ {
+ parent::__construct($params);
- if ($conn)
+ if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
{
- // Check if a user wants to run queries in dry, i.e. run the
- // queries but not commit them.
- if (isset($this->auto_commit) && ! $this->auto_commit)
+ if (stripos($matches[2], 'autocommit=off') !== FALSE)
{
- cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE);
- }
- else
- {
- cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE);
- $this->auto_commit = TRUE;
+ $this->auto_commit = FALSE;
}
}
+ else
+ {
+ // If no port is defined by the user, use the default value
+ $this->port == '' OR $this->port = 33000;
+ }
+ }
- return $conn;
+ /**
+ * Non-persistent database connection
+ *
+ * @return resource
+ */
+ public function db_connect()
+ {
+ return $this->_cubrid_connect();
}
// --------------------------------------------------------------------
@@ -100,15 +97,45 @@ class CI_DB_cubrid_driver extends CI_DB {
* 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. This is calling the same
- * @cubrid_connect function will establish persisten connection
- * considering that the CCI_PCONNECT is ON.
+ * server will become persistent.
*
* @return resource
*/
public function db_pconnect()
{
- return $this->db_connect();
+ 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
+ * @return resource
+ */
+ protected function _cubrid_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);
+ }
+
+ return $conn_id;
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/interbase/interbase_driver.php b/system/database/drivers/interbase/interbase_driver.php
index 326841dc2..d8b6ae571 100644
--- a/system/database/drivers/interbase/interbase_driver.php
+++ b/system/database/drivers/interbase/interbase_driver.php
@@ -85,21 +85,6 @@ class CI_DB_interbase_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- // not implemented in Interbase/Firebird
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
* @return bool
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index 1c1b84582..912808631 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -92,21 +92,6 @@ class CI_DB_mssql_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- // not implemented in MSSQL
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
* @param string database name
@@ -554,13 +539,12 @@ class CI_DB_mssql_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
- * @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
- function _delete($table, $where = array(), $like = array(), $limit = FALSE)
+ protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 4c5d52127..041daf710 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -357,7 +357,6 @@ class CI_DB_mysqli_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
- * @access private
* @param bool
* @return string
*/
diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php
index 238a08ff8..3bc8c114c 100644
--- a/system/database/drivers/oci8/oci8_driver.php
+++ b/system/database/drivers/oci8/oci8_driver.php
@@ -78,6 +78,85 @@ class CI_DB_oci8_driver extends CI_DB {
// throw off num_fields later
public $limit_used;
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ $valid_dsns = array(
+ 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
+ // Easy Connect string (Oracle 10g+)
+ 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
+ 'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora)
+ );
+
+ /* Space characters don't have any effect when actually
+ * connecting, but can be a hassle while validating the DSN.
+ */
+ $this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn);
+
+ if ($this->dsn !== '')
+ {
+ foreach ($valid_dsns as $regexp)
+ {
+ if (preg_match($regexp, $this->dsn))
+ {
+ return;
+ }
+ }
+ }
+
+ // Legacy support for TNS in the hostname configuration field
+ $this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname);
+ if (preg_match($valid_dsns['tns'], $this->hostname))
+ {
+ $this->dsn = $this->hostname;
+ return;
+ }
+ elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE
+ && (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== ''))
+ {
+ /* If the hostname field isn't empty, doesn't contain
+ * ':' and/or '/' and if port and/or database aren't
+ * empty, then the hostname field is most likely indeed
+ * just a hostname. Therefore we'll try and build an
+ * Easy Connect string from these 3 settings, assuming
+ * that the database field is a service name.
+ */
+ $this->dsn = $this->hostname
+ .(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '')
+ .($this->database !== '' ? '/'.ltrim($this->database, '/') : '');
+
+ if (preg_match($valid_dsns['ec'], $this->dsn))
+ {
+ return;
+ }
+ }
+
+ /* At this point, we can only try and validate the hostname and
+ * database fields separately as DSNs.
+ */
+ if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname))
+ {
+ $this->dsn = $this->hostname;
+ return;
+ }
+
+ $this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database);
+ foreach ($valid_dsns as $regexp)
+ {
+ if (preg_match($regexp, $this->database))
+ {
+ return;
+ }
+ }
+
+ /* Well - OK, an empty string should work as well.
+ * PHP will try to use environment variables to
+ * determine which Oracle instance to connect to.
+ */
+ $this->dsn = '';
+ }
+
/**
* Non-persistent database connection
*
@@ -85,7 +164,9 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function db_connect()
{
- return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set);
+ return ( ! empty($this->char_set))
+ ? @oci_connect($this->username, $this->password, $this->dsn, $this->char_set)
+ : @oci_connect($this->username, $this->password, $this->dsn);
}
// --------------------------------------------------------------------
@@ -97,23 +178,9 @@ class CI_DB_oci8_driver extends CI_DB {
*/
public function db_pconnect()
{
- return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- // not implemented in oracle
- return;
+ return ( ! empty($this->char_set))
+ ? @oci_pconnect($this->username, $this->password, $this->dsn, $this->char_set)
+ : @oci_pconnect($this->username, $this->password, $this->dsn);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php
index 6704264c6..ad773117f 100644
--- a/system/database/drivers/odbc/odbc_driver.php
+++ b/system/database/drivers/odbc/odbc_driver.php
@@ -57,12 +57,17 @@ class CI_DB_odbc_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword;
-
public function __construct($params)
{
parent::__construct($params);
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
+
+ // Legacy support for DSN in the hostname field
+ if ($this->dsn == '')
+ {
+ $this->dsn = $this->hostname;
+ }
}
/**
@@ -72,7 +77,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
public function db_connect()
{
- return @odbc_connect($this->hostname, $this->username, $this->password);
+ return @odbc_connect($this->dsn, $this->username, $this->password);
}
// --------------------------------------------------------------------
@@ -84,22 +89,7 @@ class CI_DB_odbc_driver extends CI_DB {
*/
public function db_pconnect()
{
- return @odbc_pconnect($this->hostname, $this->username, $this->password);
- }
-
- // --------------------------------------------------------------------
-
- /**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- // not implemented in odbc
+ return @odbc_pconnect($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 0295b9d56..f336eb0ab 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -247,26 +247,6 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- if ($this->db->db_debug)
- {
- return $this->db->display_error('db_unsuported_feature');
- }
-
- return FALSE;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
* @return resource
@@ -504,7 +484,7 @@ class CI_DB_pdo_driver extends CI_DB {
* @param string
* @return string
*/
- function count_all($table = '')
+ public function count_all($table = '')
{
if ($table == '')
{
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);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/postgre/postgre_utility.php b/system/database/drivers/postgre/postgre_utility.php
index c6b71b4d9..cf29201ff 100644
--- a/system/database/drivers/postgre/postgre_utility.php
+++ b/system/database/drivers/postgre/postgre_utility.php
@@ -78,7 +78,7 @@ class CI_DB_postgre_utility extends CI_DB_utility {
* @param array Preferences
* @return mixed
*/
- function _backup($params = array())
+ public function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php
index bb86c2296..102c79bb3 100644
--- a/system/database/drivers/sqlite/sqlite_driver.php
+++ b/system/database/drivers/sqlite/sqlite_driver.php
@@ -106,21 +106,6 @@ class CI_DB_sqlite_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- // not implemented in SQLite
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
* @return resource
@@ -260,9 +245,9 @@ class CI_DB_sqlite_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace( array('%', '_', $this->_like_escape_chr),
- array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
- $str);
+ return str_replace(array($this->_like_escape_chr, '%', '_'),
+ array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
+ $str);
}
return $str;
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 2b9f82201..9f2f88699 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -101,21 +101,6 @@ class CI_DB_sqlsrv_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Reconnect
- *
- * Keep / reestablish the db connection if no queries have been
- * sent for a length of time exceeding the server's idle timeout
- *
- * @return void
- */
- public function reconnect()
- {
- // not implemented in MSSQL
- }
-
- // --------------------------------------------------------------------
-
- /**
* Select the database
*
* @param string database name