summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authorJonathon Hill <jhill@brandmovers.com>2012-11-12 14:51:41 +0100
committerJonathon Hill <jhill@brandmovers.com>2012-11-12 14:51:41 +0100
commit3978fc33d82dd7f778d1adbf30744f4dfac41c25 (patch)
treef32be1ae610f0cfeff65c35abecd14e8ea5cadc6 /system/database/DB_driver.php
parent275cf274860c6ed181d50b398efd3a21d7ba9135 (diff)
parenta9ab46d7a031bda304eb9b6658ffaf693b8d9bcb (diff)
Merge remote-tracking branch 'upstream/develop' into develop
Conflicts: user_guide_src/source/changelog.rst Signed-off-by: Jonathon Hill <jhill@brandmovers.com>
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php312
1 files changed, 271 insertions, 41 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index e8286aaa1..dfaf0e0c1 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Database Driver Class
@@ -40,60 +41,314 @@
*/
abstract class CI_DB_driver {
+ /**
+ * Data Source Name / Connect string
+ *
+ * @var string
+ */
public $dsn;
+
+ /**
+ * Username
+ *
+ * @var string
+ */
public $username;
+
+ /**
+ * Password
+ *
+ * @var string
+ */
public $password;
+
+ /**
+ * Hostname
+ *
+ * @var string
+ */
public $hostname;
+
+ /**
+ * Database name
+ *
+ * @var string
+ */
public $database;
+
+ /**
+ * Database driver
+ *
+ * @var string
+ */
public $dbdriver = 'mysqli';
+
+ /**
+ * Sub-driver
+ *
+ * @used-by CI_DB_pdo_driver
+ * @var string
+ */
public $subdriver;
+
+ /**
+ * Table prefix
+ *
+ * @var string
+ */
public $dbprefix = '';
+
+ /**
+ * Character set
+ *
+ * @var string
+ */
public $char_set = 'utf8';
+
+ /**
+ * Collation
+ *
+ * @var string
+ */
public $dbcollat = 'utf8_general_ci';
- public $autoinit = TRUE; // Whether to automatically initialize the DB
+
+ /**
+ * Auto-init flag
+ *
+ * Whether to automatically initialize the DB connection.
+ *
+ * @var bool
+ */
+ public $autoinit = TRUE;
+
+ /**
+ * Encryption flag/data
+ *
+ * @var mixed
+ */
public $encrypt = FALSE;
+
+ /**
+ * Swap Prefix
+ *
+ * @var string
+ */
public $swap_pre = '';
+
+ /**
+ * Database port
+ *
+ * @var int
+ */
public $port = '';
+
+ /**
+ * Persistent connection flag
+ *
+ * @var bool
+ */
public $pconnect = FALSE;
+
+ /**
+ * Connection ID
+ *
+ * @var object|resource
+ */
public $conn_id = FALSE;
+
+ /**
+ * Result ID
+ *
+ * @var object|resource
+ */
public $result_id = FALSE;
+
+ /**
+ * Debug flag
+ *
+ * Whether to display error messages.
+ *
+ * @var bool
+ */
public $db_debug = FALSE;
+
+ /**
+ * Benchmark time
+ *
+ * @var int
+ */
public $benchmark = 0;
+
+ /**
+ * Executed queries count
+ *
+ * @var int
+ */
public $query_count = 0;
+
+ /**
+ * Bind marker
+ *
+ * Character used to identify values in a prepared statement.
+ *
+ * @var string
+ */
public $bind_marker = '?';
+
+ /**
+ * Save queries flag
+ *
+ * Whether to keep an in-memory history of queries for debugging purposes.
+ *
+ * @var bool
+ */
public $save_queries = TRUE;
+
+ /**
+ * Queries list
+ *
+ * @see CI_DB_driver::$save_queries
+ * @var string[]
+ */
public $queries = array();
+
+ /**
+ * Query times
+ *
+ * A list of times that queries took to execute.
+ *
+ * @var array
+ */
public $query_times = array();
+
+ /**
+ * Data cache
+ *
+ * An internal generic value cache.
+ *
+ * @var array
+ */
public $data_cache = array();
+ /**
+ * Transaction enabled flag
+ *
+ * @var bool
+ */
public $trans_enabled = TRUE;
+
+ /**
+ * Strict transaction mode flag
+ *
+ * @var bool
+ */
public $trans_strict = TRUE;
+
+ /**
+ * Transaction depth level
+ *
+ * @var int
+ */
protected $_trans_depth = 0;
- protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
+ /**
+ * Transaction status flag
+ *
+ * Used with transactions to determine if a rollback should occur.
+ *
+ * @var bool
+ */
+ protected $_trans_status = TRUE;
+
+ /**
+ * Cache On flag
+ *
+ * @var bool
+ */
public $cache_on = FALSE;
+
+ /**
+ * Cache directory path
+ *
+ * @var bool
+ */
public $cachedir = '';
+
+ /**
+ * Cache auto-delete flag
+ *
+ * @var bool
+ */
public $cache_autodel = FALSE;
- public $CACHE; // The cache class object
+ /**
+ * DB Cache object
+ *
+ * @see CI_DB_cache
+ * @var object
+ */
+ public $CACHE;
+
+ /**
+ * Protect identifiers flag
+ *
+ * @var bool
+ */
protected $_protect_identifiers = TRUE;
- protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
- // clause and character used for LIKE escape sequences
+ /**
+ * List of reserved identifiers
+ *
+ * Identifiers that must NOT be escaped.
+ *
+ * @var string[]
+ */
+ protected $_reserved_identifiers = array('*');
+
+ /**
+ * Identifier escape character
+ *
+ * @var string
+ */
+ protected $_escape_char = '"';
+
+ /**
+ * ESCAPE statement string
+ *
+ * @var string
+ */
protected $_like_escape_str = " ESCAPE '%s' ";
+
+ /**
+ * ESCAPE character
+ *
+ * @var string
+ */
protected $_like_escape_chr = '!';
/**
- * The syntax to count rows is slightly different across different
- * database engines, so this string appears in each driver and is
- * used for the count_all() and count_all_results() functions.
+ * ORDER BY random keyword
+ *
+ * @var string
+ */
+ protected $_random_keyword = ' RAND()';
+
+ /**
+ * COUNT string
+ *
+ * @used-by CI_DB_driver::count_all()
+ * @used-by CI_DB_query_builder::count_all_results()
+ *
+ * @var string
*/
protected $_count_string = 'SELECT COUNT(*) AS ';
+ // --------------------------------------------------------------------
+
/**
- * Constructor
+ * Class constructor
*
- * @param array
+ * @param array $params
* @return void
*/
public function __construct($params)
@@ -981,7 +1236,7 @@ abstract class CI_DB_driver {
*/
public function escape_identifiers($item)
{
- if ($this->_escape_char === '' OR empty($item))
+ if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers))
{
return $item;
}
@@ -1080,43 +1335,19 @@ abstract class CI_DB_driver {
*/
public function update_string($table, $data, $where)
{
- if ($where === '')
+ if (empty($where))
{
return FALSE;
}
+ $this->where($where);
+
$fields = array();
foreach ($data as $key => $val)
{
$fields[$this->protect_identifiers($key)] = $this->escape($val);
}
- if ( ! is_array($where))
- {
- $dest = array($where);
- }
- else
- {
- $dest = array();
- foreach ($where as $key => $val)
- {
- $prefix = (count($dest) === 0) ? '' : ' AND ';
- $key = $this->protect_identifiers($key);
-
- if ($val !== '')
- {
- if ( ! $this->_has_operator($key))
- {
- $key .= ' =';
- }
-
- $val = ' '.$this->escape($val);
- }
-
- $dest[] = $prefix.$key.$val;
- }
- }
-
return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
}
@@ -1198,8 +1429,7 @@ abstract class CI_DB_driver {
/**
* Enables a native PHP function to be run, using a platform agnostic wrapper.
*
- * @param string $function the function name
- * @param mixed $param,... optional parameters needed by the function
+ * @param string $function Function name
* @return mixed
*/
public function call_function($function)