summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/pdo/pdo_driver.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-04-09 15:30:36 +0200
committerAndrey Andreev <narf@bofh.bg>2012-04-09 15:30:36 +0200
commit871a6f979e4291365c40247158ccde8fccca3ae5 (patch)
tree46b2ec89456d0dc1aec053d1feaf78c1e2b97d47 /system/database/drivers/pdo/pdo_driver.php
parent8e286e96af6f0487e9339d5d87c35a539a6879c6 (diff)
parent918be7963f6fa3461d612ea7ca4c9774c12f9da5 (diff)
Merge upstream branch
Diffstat (limited to 'system/database/drivers/pdo/pdo_driver.php')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php121
1 files changed, 31 insertions, 90 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 919bb9c00..60151b900 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -183,6 +183,8 @@ class CI_DB_pdo_driver extends CI_DB {
}
}
+ // --------------------------------------------------------------------
+
/**
* Non-persistent database connection
*
@@ -190,9 +192,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function db_connect()
{
- $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
-
- return $this->pdo_connect();
+ return $this->_pdo_connect();
}
// --------------------------------------------------------------------
@@ -204,10 +204,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function db_pconnect()
{
- $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
- $this->options[PDO::ATTR_PERSISTENT] = TRUE;
-
- return $this->pdo_connect();
+ return $this->_pdo_connect(TRUE);
}
// --------------------------------------------------------------------
@@ -215,20 +212,29 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* PDO connection
*
+ * @param bool
* @return object
*/
- public function pdo_connect()
+ protected function _pdo_connect($persistent = FALSE)
{
- // Refer : http://php.net/manual/en/ref.pdo-mysql.connection.php
- if ($this->pdodriver === 'mysql' && ! is_php('5.3.6'))
+ $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
+ $persistent === FALSE OR $this->options[PDO::ATTR_PERSISTENT] = TRUE;
+
+ /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN
+ * on connect - it was ignored. This is a work-around for the issue.
+ *
+ * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
+ */
+ if ($this->subdriver === 'mysql' && ! is_php('5.3.6') && ! empty($this->char_set))
{
- $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES $this->char_set COLLATE '$this->dbcollat'";
+ $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set
+ .( ! empty($this->db_collat) ? " COLLATE '".$this->dbcollat."'" : '');
}
// Connecting...
try
{
- $db = new PDO($this->dsn, $this->username, $this->password, $this->options);
+ return new PDO($this->dsn, $this->username, $this->password, $this->options);
}
catch (PDOException $e)
{
@@ -239,8 +245,6 @@ class CI_DB_pdo_driver extends CI_DB {
return FALSE;
}
-
- return $db;
}
// --------------------------------------------------------------------
@@ -267,18 +271,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
protected function _execute($sql)
{
- $result_id = $this->conn_id->query($sql);
-
- if (is_object($result_id))
- {
- $this->affect_rows = $result_id->rowCount();
- }
- else
- {
- $this->affect_rows = 0;
- }
-
- return $result_id;
+ return $this->conn_id->query($sql);
}
// --------------------------------------------------------------------
@@ -290,13 +283,8 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -304,7 +292,7 @@ class CI_DB_pdo_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = (bool) ($test_mode === TRUE);
+ $this->_trans_failure = ($test_mode === TRUE);
return $this->conn_id->beginTransaction();
}
@@ -318,20 +306,13 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- $ret = $this->conn->commit();
-
- return $ret;
+ return $this->conn_id->commit();
}
// --------------------------------------------------------------------
@@ -343,20 +324,13 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- $ret = $this->conn_id->rollBack();
-
- return $ret;
+ return $this->conn_id->rollBack();
}
// --------------------------------------------------------------------
@@ -380,10 +354,10 @@ class CI_DB_pdo_driver extends CI_DB {
return $str;
}
- //Escape the string
+ // Escape the string
$str = $this->conn_id->quote($str);
- //If there are duplicated quotes, trim them away
+ // If there are duplicated quotes, trim them away
if (strpos($str, "'") === 0)
{
$str = substr($str, 1, -1);
@@ -409,7 +383,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
public function affected_rows()
{
- return $this->affect_rows;
+ return is_object($this->result_id) ? $this->result_id->rowCount() : 0;
}
// --------------------------------------------------------------------
@@ -417,6 +391,7 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
*
+ * @param string
* @return int
*/
public function insert_id($name = NULL)
@@ -666,40 +641,6 @@ class CI_DB_pdo_driver extends CI_DB {
// --------------------------------------------------------------------
/**
- * Delete statement
- *
- * Generates a platform-specific delete string from the supplied data
- *
- * @param string the table name
- * @param array the where clause
- * @param string the limit clause
- * @return string
- */
- protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
- {
- $conditions = '';
-
- if (count($where) > 0 OR count($like) > 0)
- {
- $conditions = "\nWHERE ";
- $conditions .= implode("\n", $this->ar_where);
-
- if (count($where) > 0 && count($like) > 0)
- {
- $conditions .= " AND ";
- }
-
- $conditions .= implode("\n", $like);
- }
-
- $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
-
- return 'DELETE FROM '.$table.$conditions.$limit;
- }
-
- // --------------------------------------------------------------------
-
- /**
* Limit string
*
* Generates a platform-specific LIMIT clause
@@ -731,12 +672,12 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Close DB Connection
*
- * @param resource
+ * @param object
* @return void
*/
protected function _close($conn_id)
{
- $this->conn_id = null;
+ $this->conn_id = NULL;
}
}