Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Database Driver Class |
| 30 | * |
| 31 | * This is the platform-independent base DB implementation class. |
| 32 | * This class will not be called directly. Rather, the adapter |
| 33 | * class for the specific database will extend and instantiate it. |
| 34 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Drivers |
| 37 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 38 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | * @link http://codeigniter.com/user_guide/database/ |
| 40 | */ |
| 41 | class CI_DB_driver { |
| 42 | |
Andrey Andreev | d1add43 | 2012-03-06 20:26:01 +0200 | [diff] [blame] | 43 | public $username; |
| 44 | public $password; |
| 45 | public $hostname; |
| 46 | public $database; |
| 47 | public $dbdriver = 'mysql'; |
| 48 | public $dbprefix = ''; |
| 49 | public $char_set = 'utf8'; |
| 50 | public $dbcollat = 'utf8_general_ci'; |
| 51 | public $autoinit = TRUE; // Whether to automatically initialize the DB |
| 52 | public $swap_pre = ''; |
| 53 | public $port = ''; |
| 54 | public $pconnect = FALSE; |
| 55 | public $conn_id = FALSE; |
| 56 | public $result_id = FALSE; |
| 57 | public $db_debug = FALSE; |
| 58 | public $benchmark = 0; |
| 59 | public $query_count = 0; |
| 60 | public $bind_marker = '?'; |
| 61 | public $save_queries = TRUE; |
| 62 | public $queries = array(); |
| 63 | public $query_times = array(); |
| 64 | public $data_cache = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | |
Andrey Andreev | d1add43 | 2012-03-06 20:26:01 +0200 | [diff] [blame] | 66 | public $trans_enabled = TRUE; |
| 67 | public $trans_strict = TRUE; |
| 68 | protected $_trans_depth = 0; |
| 69 | protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 70 | |
Andrey Andreev | d1add43 | 2012-03-06 20:26:01 +0200 | [diff] [blame] | 71 | public $cache_on = FALSE; |
| 72 | public $cachedir = ''; |
| 73 | public $cache_autodel = FALSE; |
| 74 | public $CACHE; // The cache class object |
| 75 | |
| 76 | protected $_protect_identifiers = TRUE; |
| 77 | protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped |
| 78 | |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 79 | public function __construct($params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | { |
| 81 | if (is_array($params)) |
| 82 | { |
| 83 | foreach ($params as $key => $val) |
| 84 | { |
| 85 | $this->$key = $val; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | log_message('debug', 'Database Driver Class Initialized'); |
| 90 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 91 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 92 | // -------------------------------------------------------------------- |
| 93 | |
| 94 | /** |
| 95 | * Initialize Database Settings |
| 96 | * |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 97 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 98 | */ |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 99 | public function initialize() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | { |
| 101 | // If an existing connection resource is available |
| 102 | // there is no need to connect and select the database |
| 103 | if (is_resource($this->conn_id) OR is_object($this->conn_id)) |
| 104 | { |
| 105 | return TRUE; |
| 106 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 107 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | // ---------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 109 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | // Connect to the database and set the connection ID |
| 111 | $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); |
| 112 | |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 113 | // No connection resource? Check if there is a failover else throw an error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | if ( ! $this->conn_id) |
| 115 | { |
Felix Balfoort | 5d581b6 | 2011-11-29 15:53:01 +0100 | [diff] [blame] | 116 | // Check if there is a failover set |
| 117 | if ( ! empty($this->failover) && is_array($this->failover)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | { |
Felix Balfoort | 5d581b6 | 2011-11-29 15:53:01 +0100 | [diff] [blame] | 119 | // Go over all the failovers |
| 120 | foreach ($this->failover as $failover) |
| 121 | { |
| 122 | // Replace the current settings with those of the failover |
| 123 | foreach ($failover as $key => $val) |
| 124 | { |
| 125 | $this->$key = $val; |
| 126 | } |
| 127 | |
| 128 | // Try to connect |
| 129 | $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect(); |
| 130 | |
| 131 | // If a connection is made break the foreach loop |
| 132 | if ($this->conn_id) |
| 133 | { |
| 134 | break; |
| 135 | } |
| 136 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | } |
Felix Balfoort | 5d581b6 | 2011-11-29 15:53:01 +0100 | [diff] [blame] | 138 | |
| 139 | // We still don't have a connection? |
| 140 | if ( ! $this->conn_id) |
| 141 | { |
| 142 | log_message('error', 'Unable to connect to the database'); |
| 143 | |
| 144 | if ($this->db_debug) |
| 145 | { |
| 146 | $this->display_error('db_unable_to_connect'); |
| 147 | } |
| 148 | return FALSE; |
| 149 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // ---------------------------------------------------------------- |
| 153 | |
| 154 | // Select the DB... assuming a database name is specified in the config file |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 155 | if ($this->database !== '' && ! $this->db_select()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 156 | { |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 157 | log_message('error', 'Unable to select database: '.$this->database); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 158 | |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 159 | if ($this->db_debug) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | { |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 161 | $this->display_error('db_unable_to_select', $this->database); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | } |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 163 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Andrey Andreev | 82e8ac1 | 2012-02-22 19:35:34 +0200 | [diff] [blame] | 166 | // Now we set the character set and that's all |
| 167 | return $this->db_set_charset($this->char_set, $this->dbcollat); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | // -------------------------------------------------------------------- |
| 171 | |
| 172 | /** |
| 173 | * Set client character set |
| 174 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 175 | * @param string |
| 176 | * @param string |
Andrey Andreev | 063f596 | 2012-02-27 12:20:52 +0200 | [diff] [blame] | 177 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 178 | */ |
Andrey Andreev | 063f596 | 2012-02-27 12:20:52 +0200 | [diff] [blame] | 179 | public function db_set_charset($charset, $collation = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 180 | { |
Andrey Andreev | 063f596 | 2012-02-27 12:20:52 +0200 | [diff] [blame] | 181 | if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset, $collation)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | { |
Andrey Andreev | 063f596 | 2012-02-27 12:20:52 +0200 | [diff] [blame] | 183 | log_message('error', 'Unable to set database connection charset: '.$charset); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 184 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | if ($this->db_debug) |
| 186 | { |
Andrey Andreev | 063f596 | 2012-02-27 12:20:52 +0200 | [diff] [blame] | 187 | $this->display_error('db_unable_to_set_charset', $charset); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 189 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | return FALSE; |
| 191 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 192 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | return TRUE; |
| 194 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 195 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | // -------------------------------------------------------------------- |
| 197 | |
| 198 | /** |
| 199 | * The name of the platform in use (mysql, mssql, etc...) |
| 200 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 201 | * @return string |
| 202 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 203 | public function platform() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 204 | { |
| 205 | return $this->dbdriver; |
| 206 | } |
| 207 | |
| 208 | // -------------------------------------------------------------------- |
| 209 | |
| 210 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 211 | * Database version number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | * |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 213 | * Returns a string containing the version of the database being used. |
| 214 | * Most drivers will override this method. |
| 215 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 216 | * @return string |
| 217 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 218 | public function version() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 220 | if (isset($this->data_cache['version'])) |
| 221 | { |
| 222 | return $this->data_cache['version']; |
| 223 | } |
| 224 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | if (FALSE === ($sql = $this->_version())) |
| 226 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 227 | return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | } |
Derek Allard | 3683f77 | 2009-12-16 17:32:33 +0000 | [diff] [blame] | 229 | |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 230 | $query = $this->query($sql); |
| 231 | $query = $query->row(); |
| 232 | return $this->data_cache['version'] = $query->ver; |
| 233 | } |
Derek Allard | 3683f77 | 2009-12-16 17:32:33 +0000 | [diff] [blame] | 234 | |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 235 | // -------------------------------------------------------------------- |
| 236 | |
| 237 | /** |
| 238 | * Version number query string |
| 239 | * |
| 240 | * @return string |
| 241 | */ |
| 242 | protected function _version() |
| 243 | { |
| 244 | return 'SELECT VERSION() AS ver'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 246 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 247 | // -------------------------------------------------------------------- |
| 248 | |
| 249 | /** |
| 250 | * Execute the query |
| 251 | * |
| 252 | * Accepts an SQL string as input and returns a result object upon |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 253 | * successful execution of a "read" type query. Returns boolean TRUE |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 254 | * upon successful execution of a "write" type query. Returns boolean |
| 255 | * FALSE upon failure, and if the $db_debug variable is set to TRUE |
| 256 | * will raise an error. |
| 257 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 258 | * @param string An SQL query string |
| 259 | * @param array An array of binding data |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 260 | * @return mixed |
| 261 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 262 | public function query($sql, $binds = FALSE, $return_object = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | { |
| 264 | if ($sql == '') |
| 265 | { |
Niklas Nilsson | d2018ee | 2011-08-30 13:39:42 +0200 | [diff] [blame] | 266 | log_message('error', 'Invalid query: '.$sql); |
| 267 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | if ($this->db_debug) |
| 269 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | return $this->display_error('db_invalid_query'); |
| 271 | } |
| 272 | return FALSE; |
| 273 | } |
| 274 | |
| 275 | // Verify table prefix and replace if necessary |
| 276 | if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) ) |
Derek Jones | e779220 | 2010-03-02 17:24:46 -0600 | [diff] [blame] | 277 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | $sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql); |
| 279 | } |
Derek Jones | e779220 | 2010-03-02 17:24:46 -0600 | [diff] [blame] | 280 | |
Ryan Dial | ef7474c | 2012-03-01 16:11:36 -0500 | [diff] [blame] | 281 | // Compile binds if needed |
| 282 | if ($binds !== FALSE) |
| 283 | { |
| 284 | $sql = $this->compile_binds($sql, $binds); |
| 285 | } |
| 286 | |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 287 | // Is query caching enabled? If the query is a "read type" |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | // we will load the caching class and return the previously |
| 289 | // cached query if it exists |
| 290 | if ($this->cache_on == TRUE AND stristr($sql, 'SELECT')) |
| 291 | { |
| 292 | if ($this->_cache_init()) |
| 293 | { |
| 294 | $this->load_rdriver(); |
| 295 | if (FALSE !== ($cache = $this->CACHE->read($sql))) |
| 296 | { |
| 297 | return $cache; |
| 298 | } |
| 299 | } |
| 300 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 301 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 302 | // Save the query for debugging |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | if ($this->save_queries == TRUE) |
| 304 | { |
| 305 | $this->queries[] = $sql; |
| 306 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 307 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | // Start the Query Timer |
| 309 | $time_start = list($sm, $ss) = explode(' ', microtime()); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 310 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | // Run the Query |
| 312 | if (FALSE === ($this->result_id = $this->simple_query($sql))) |
| 313 | { |
| 314 | if ($this->save_queries == TRUE) |
| 315 | { |
| 316 | $this->query_times[] = 0; |
| 317 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 318 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | // This will trigger a rollback if transactions are being used |
| 320 | $this->_trans_status = FALSE; |
| 321 | |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 322 | // Grab the error now, as we might run some additional queries before displaying the error |
| 323 | $error = $this->error(); |
Niklas Nilsson | d2018ee | 2011-08-30 13:39:42 +0200 | [diff] [blame] | 324 | |
| 325 | // Log errors |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 326 | log_message('error', 'Query error: '.$error['message']); |
Niklas Nilsson | d2018ee | 2011-08-30 13:39:42 +0200 | [diff] [blame] | 327 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 328 | if ($this->db_debug) |
| 329 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | // We call this function in order to roll-back queries |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 331 | // if transactions are enabled. If we don't call this here |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 332 | // the error message will trigger an exit, causing the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | // transactions to remain in limbo. |
| 334 | $this->trans_complete(); |
| 335 | |
Niklas Nilsson | d2018ee | 2011-08-30 13:39:42 +0200 | [diff] [blame] | 336 | // Display errors |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | return $this->display_error( |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 338 | array( |
| 339 | 'Error Number: '.$error['code'], |
| 340 | $error['message'], |
| 341 | $sql |
| 342 | ) |
| 343 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 345 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | return FALSE; |
| 347 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 348 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | // Stop and aggregate the query time results |
| 350 | $time_end = list($em, $es) = explode(' ', microtime()); |
| 351 | $this->benchmark += ($em + $es) - ($sm + $ss); |
| 352 | |
| 353 | if ($this->save_queries == TRUE) |
| 354 | { |
| 355 | $this->query_times[] = ($em + $es) - ($sm + $ss); |
| 356 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 357 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | // Increment the query counter |
| 359 | $this->query_count++; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 360 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | // Was the query a "write" type? |
| 362 | // If so we'll simply return true |
| 363 | if ($this->is_write_type($sql) === TRUE) |
| 364 | { |
| 365 | // If caching is enabled we'll auto-cleanup any |
| 366 | // existing files related to this particular URI |
| 367 | if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init()) |
| 368 | { |
| 369 | $this->CACHE->delete(); |
| 370 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 371 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 372 | return TRUE; |
| 373 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 374 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 375 | // Return TRUE if we don't need to create a result object |
| 376 | // Currently only the Oracle driver uses this when stored |
| 377 | // procedures are used |
| 378 | if ($return_object !== TRUE) |
| 379 | { |
| 380 | return TRUE; |
| 381 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 382 | |
| 383 | // Load and instantiate the result driver |
Andrey Andreev | 57bdeb6 | 2012-03-05 15:59:16 +0200 | [diff] [blame] | 384 | $driver = $this->load_rdriver(); |
| 385 | $RES = new $driver($this); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 386 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 387 | $RES->num_rows = $RES->num_rows(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 388 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 389 | // Is query caching enabled? If so, we'll serialize the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 390 | // result object and save it to a cache file. |
| 391 | if ($this->cache_on == TRUE AND $this->_cache_init()) |
| 392 | { |
| 393 | // We'll create a new instance of the result object |
| 394 | // only without the platform specific driver since |
| 395 | // we can't use it with cached data (the query result |
| 396 | // resource ID won't be any good once we've cached the |
| 397 | // result object, so we'll have to compile the data |
| 398 | // and save it) |
| 399 | $CR = new CI_DB_result(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 400 | $CR->num_rows = $RES->num_rows(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | $CR->result_object = $RES->result_object(); |
| 402 | $CR->result_array = $RES->result_array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 403 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | // Reset these since cached objects can not utilize resource IDs. |
| 405 | $CR->conn_id = NULL; |
| 406 | $CR->result_id = NULL; |
| 407 | |
| 408 | $this->CACHE->write($sql, $CR); |
| 409 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 410 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 411 | return $RES; |
| 412 | } |
| 413 | |
| 414 | // -------------------------------------------------------------------- |
| 415 | |
| 416 | /** |
| 417 | * Load the result drivers |
| 418 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 419 | * @return string the name of the result class |
| 420 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 421 | public function load_rdriver() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 422 | { |
| 423 | $driver = 'CI_DB_'.$this->dbdriver.'_result'; |
| 424 | |
| 425 | if ( ! class_exists($driver)) |
| 426 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 427 | include_once(BASEPATH.'database/DB_result.php'); |
| 428 | include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 429 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 430 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | return $driver; |
| 432 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 433 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 434 | // -------------------------------------------------------------------- |
| 435 | |
| 436 | /** |
| 437 | * Simple Query |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 438 | * This is a simplified version of the query() function. Internally |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | * we only use it when running transaction commands since they do |
| 440 | * not require all the features of the main query() function. |
| 441 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | * @param string the sql query |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 443 | * @return mixed |
| 444 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 445 | public function simple_query($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 446 | { |
| 447 | if ( ! $this->conn_id) |
| 448 | { |
| 449 | $this->initialize(); |
| 450 | } |
| 451 | |
| 452 | return $this->_execute($sql); |
| 453 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 454 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 455 | // -------------------------------------------------------------------- |
| 456 | |
| 457 | /** |
| 458 | * Disable Transactions |
| 459 | * This permits transactions to be disabled at run-time. |
| 460 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 461 | * @return void |
| 462 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 463 | public function trans_off() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 464 | { |
| 465 | $this->trans_enabled = FALSE; |
| 466 | } |
| 467 | |
| 468 | // -------------------------------------------------------------------- |
| 469 | |
| 470 | /** |
| 471 | * Enable/disable Transaction Strict Mode |
| 472 | * When strict mode is enabled, if you are running multiple groups of |
| 473 | * transactions, if one group fails all groups will be rolled back. |
| 474 | * If strict mode is disabled, each group is treated autonomously, meaning |
| 475 | * a failure of one group will not affect any others |
| 476 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 477 | * @return void |
| 478 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 479 | public function trans_strict($mode = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 480 | { |
| 481 | $this->trans_strict = is_bool($mode) ? $mode : TRUE; |
| 482 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 483 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 484 | // -------------------------------------------------------------------- |
| 485 | |
| 486 | /** |
| 487 | * Start Transaction |
| 488 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 489 | * @return void |
| 490 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 491 | public function trans_start($test_mode = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 492 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 493 | if ( ! $this->trans_enabled) |
| 494 | { |
| 495 | return FALSE; |
| 496 | } |
| 497 | |
| 498 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 499 | if ($this->_trans_depth > 0) |
| 500 | { |
| 501 | $this->_trans_depth += 1; |
| 502 | return; |
| 503 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 504 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 505 | $this->trans_begin($test_mode); |
Jacob Terry | 07fcedf | 2011-11-22 11:21:36 -0500 | [diff] [blame] | 506 | $this->_trans_depth += 1; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | // -------------------------------------------------------------------- |
| 510 | |
| 511 | /** |
| 512 | * Complete Transaction |
| 513 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 514 | * @return bool |
| 515 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 516 | public function trans_complete() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | { |
| 518 | if ( ! $this->trans_enabled) |
| 519 | { |
| 520 | return FALSE; |
| 521 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 522 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 523 | // When transactions are nested we only begin/commit/rollback the outermost ones |
| 524 | if ($this->_trans_depth > 1) |
| 525 | { |
| 526 | $this->_trans_depth -= 1; |
| 527 | return TRUE; |
| 528 | } |
Jacob Terry | 07fcedf | 2011-11-22 11:21:36 -0500 | [diff] [blame] | 529 | else |
| 530 | { |
| 531 | $this->_trans_depth = 0; |
| 532 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 533 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 534 | // The query() function will set this flag to FALSE in the event that a query failed |
| 535 | if ($this->_trans_status === FALSE) |
| 536 | { |
| 537 | $this->trans_rollback(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 538 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 539 | // If we are NOT running in strict mode, we will reset |
| 540 | // the _trans_status flag so that subsequent groups of transactions |
| 541 | // will be permitted. |
| 542 | if ($this->trans_strict === FALSE) |
| 543 | { |
| 544 | $this->_trans_status = TRUE; |
| 545 | } |
| 546 | |
| 547 | log_message('debug', 'DB Transaction Failure'); |
| 548 | return FALSE; |
| 549 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 550 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | $this->trans_commit(); |
| 552 | return TRUE; |
| 553 | } |
| 554 | |
| 555 | // -------------------------------------------------------------------- |
| 556 | |
| 557 | /** |
| 558 | * Lets you retrieve the transaction flag to determine if it has failed |
| 559 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 560 | * @return bool |
| 561 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 562 | public function trans_status() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 563 | { |
| 564 | return $this->_trans_status; |
| 565 | } |
| 566 | |
| 567 | // -------------------------------------------------------------------- |
| 568 | |
| 569 | /** |
| 570 | * Compile Bindings |
| 571 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 572 | * @param string the sql statement |
| 573 | * @param array an array of bind data |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 574 | * @return string |
| 575 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 576 | public function compile_binds($sql, $binds) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 577 | { |
| 578 | if (strpos($sql, $this->bind_marker) === FALSE) |
| 579 | { |
| 580 | return $sql; |
| 581 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 582 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 583 | if ( ! is_array($binds)) |
| 584 | { |
| 585 | $binds = array($binds); |
| 586 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 587 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 588 | // Get the sql segments around the bind markers |
| 589 | $segments = explode($this->bind_marker, $sql); |
| 590 | |
| 591 | // The count of bind should be 1 less then the count of segments |
| 592 | // If there are more bind arguments trim it down |
| 593 | if (count($binds) >= count($segments)) { |
| 594 | $binds = array_slice($binds, 0, count($segments)-1); |
| 595 | } |
| 596 | |
| 597 | // Construct the binded query |
| 598 | $result = $segments[0]; |
| 599 | $i = 0; |
| 600 | foreach ($binds as $bind) |
| 601 | { |
| 602 | $result .= $this->escape($bind); |
| 603 | $result .= $segments[++$i]; |
| 604 | } |
| 605 | |
| 606 | return $result; |
| 607 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 608 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | // -------------------------------------------------------------------- |
| 610 | |
| 611 | /** |
| 612 | * Determines if a query is a "write" type. |
| 613 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 614 | * @param string An SQL query string |
Andrey Andreev | 67f71a4 | 2012-03-01 16:18:42 +0200 | [diff] [blame] | 615 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 616 | */ |
Andrey Andreev | 67f71a4 | 2012-03-01 16:18:42 +0200 | [diff] [blame] | 617 | public function is_write_type($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 618 | { |
Andrey Andreev | 5fa7298 | 2012-03-03 04:13:20 +0200 | [diff] [blame] | 619 | return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|OPTIMIZE|REINDEX)\s+/i', $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 621 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | // -------------------------------------------------------------------- |
| 623 | |
| 624 | /** |
| 625 | * Calculate the aggregate query elapsed time |
| 626 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 627 | * @param int The number of decimal places |
| 628 | * @return int |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 629 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 630 | public function elapsed_time($decimals = 6) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 631 | { |
| 632 | return number_format($this->benchmark, $decimals); |
| 633 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 634 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 635 | // -------------------------------------------------------------------- |
| 636 | |
| 637 | /** |
| 638 | * Returns the total number of queries |
| 639 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 640 | * @return int |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 641 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 642 | public function total_queries() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 643 | { |
| 644 | return $this->query_count; |
| 645 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 646 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 647 | // -------------------------------------------------------------------- |
| 648 | |
| 649 | /** |
| 650 | * Returns the last query that was executed |
| 651 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 652 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 653 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 654 | public function last_query() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 655 | { |
| 656 | return end($this->queries); |
| 657 | } |
| 658 | |
| 659 | // -------------------------------------------------------------------- |
| 660 | |
| 661 | /** |
| 662 | * "Smart" Escape String |
| 663 | * |
| 664 | * Escapes data based on type |
| 665 | * Sets boolean and null types |
| 666 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 667 | * @param string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 668 | * @return mixed |
| 669 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 670 | public function escape($str) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 671 | { |
Derek Jones | a377bdd | 2009-02-11 18:55:24 +0000 | [diff] [blame] | 672 | if (is_string($str)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 673 | { |
Derek Jones | a377bdd | 2009-02-11 18:55:24 +0000 | [diff] [blame] | 674 | $str = "'".$this->escape_str($str)."'"; |
| 675 | } |
| 676 | elseif (is_bool($str)) |
| 677 | { |
| 678 | $str = ($str === FALSE) ? 0 : 1; |
| 679 | } |
| 680 | elseif (is_null($str)) |
| 681 | { |
| 682 | $str = 'NULL'; |
| 683 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 684 | |
| 685 | return $str; |
| 686 | } |
| 687 | |
| 688 | // -------------------------------------------------------------------- |
Derek Jones | e779220 | 2010-03-02 17:24:46 -0600 | [diff] [blame] | 689 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 690 | /** |
Derek Jones | bdc7fb9 | 2009-02-20 21:55:10 +0000 | [diff] [blame] | 691 | * Escape LIKE String |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 692 | * |
| 693 | * Calls the individual driver for platform |
| 694 | * specific escaping for LIKE conditions |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 695 | * |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 696 | * @param string |
| 697 | * @return mixed |
| 698 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 699 | public function escape_like_str($str) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 700 | { |
| 701 | return $this->escape_str($str, TRUE); |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 702 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 703 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 704 | // -------------------------------------------------------------------- |
Derek Jones | e779220 | 2010-03-02 17:24:46 -0600 | [diff] [blame] | 705 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 706 | /** |
| 707 | * Primary |
| 708 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 709 | * Retrieves the primary key. It assumes that the row in the first |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 710 | * position is the primary key |
| 711 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 712 | * @param string the table name |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 713 | * @return string |
| 714 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 715 | public function primary($table = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 716 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 717 | $fields = $this->list_fields($table); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 718 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 719 | if ( ! is_array($fields)) |
| 720 | { |
| 721 | return FALSE; |
| 722 | } |
| 723 | |
| 724 | return current($fields); |
| 725 | } |
| 726 | |
| 727 | // -------------------------------------------------------------------- |
| 728 | |
| 729 | /** |
| 730 | * Returns an array of table names |
| 731 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 732 | * @return array |
| 733 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 734 | public function list_tables($constrain_by_prefix = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 735 | { |
| 736 | // Is there a cached result? |
| 737 | if (isset($this->data_cache['table_names'])) |
| 738 | { |
| 739 | return $this->data_cache['table_names']; |
| 740 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 741 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 742 | if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix))) |
| 743 | { |
| 744 | if ($this->db_debug) |
| 745 | { |
| 746 | return $this->display_error('db_unsupported_function'); |
| 747 | } |
| 748 | return FALSE; |
| 749 | } |
| 750 | |
| 751 | $retval = array(); |
| 752 | $query = $this->query($sql); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 753 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 754 | if ($query->num_rows() > 0) |
| 755 | { |
Taufan Aditya | 1820933 | 2012-02-09 16:07:27 +0700 | [diff] [blame] | 756 | $table = FALSE; |
| 757 | $rows = $query->result_array(); |
| 758 | $key = (($row = current($rows)) && in_array('table_name', array_map('strtolower', array_keys($row)))); |
| 759 | |
| 760 | if ($key) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 761 | { |
Taufan Aditya | 1820933 | 2012-02-09 16:07:27 +0700 | [diff] [blame] | 762 | $table = array_key_exists('TABLE_NAME', $row) ? 'TABLE_NAME' : 'table_name'; |
| 763 | } |
| 764 | |
| 765 | foreach ($rows as $row) |
| 766 | { |
| 767 | $retval[] = ( ! $table) ? current($row) : $row[$table]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | $this->data_cache['table_names'] = $retval; |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 772 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 773 | return $this->data_cache['table_names']; |
| 774 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 775 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 776 | // -------------------------------------------------------------------- |
| 777 | |
| 778 | /** |
| 779 | * Determine if a particular table exists |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 780 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 781 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 782 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 783 | public function table_exists($table_name) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 784 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 785 | return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 786 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 787 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 788 | // -------------------------------------------------------------------- |
| 789 | |
| 790 | /** |
| 791 | * Fetch MySQL Field Names |
| 792 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 793 | * @param string the table name |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 794 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 795 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 796 | public function list_fields($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 797 | { |
| 798 | // Is there a cached result? |
| 799 | if (isset($this->data_cache['field_names'][$table])) |
| 800 | { |
| 801 | return $this->data_cache['field_names'][$table]; |
| 802 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 803 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 804 | if ($table == '') |
| 805 | { |
| 806 | if ($this->db_debug) |
| 807 | { |
| 808 | return $this->display_error('db_field_param_missing'); |
| 809 | } |
| 810 | return FALSE; |
| 811 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 812 | |
Greg Aker | 1edde30 | 2010-01-26 00:17:01 +0000 | [diff] [blame] | 813 | if (FALSE === ($sql = $this->_list_columns($table))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 814 | { |
| 815 | if ($this->db_debug) |
| 816 | { |
| 817 | return $this->display_error('db_unsupported_function'); |
| 818 | } |
| 819 | return FALSE; |
| 820 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 821 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 822 | $query = $this->query($sql); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 823 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 824 | $retval = array(); |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 825 | foreach ($query->result_array() as $row) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 826 | { |
| 827 | if (isset($row['COLUMN_NAME'])) |
| 828 | { |
| 829 | $retval[] = $row['COLUMN_NAME']; |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | $retval[] = current($row); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 834 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 835 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 836 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 837 | $this->data_cache['field_names'][$table] = $retval; |
| 838 | return $this->data_cache['field_names'][$table]; |
| 839 | } |
| 840 | |
| 841 | // -------------------------------------------------------------------- |
| 842 | |
| 843 | /** |
| 844 | * Determine if a particular field exists |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 845 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 846 | * @param string |
| 847 | * @param string |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 848 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 849 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 850 | public function field_exists($field_name, $table_name) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 851 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 852 | return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE; |
| 853 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 854 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 855 | // -------------------------------------------------------------------- |
| 856 | |
| 857 | /** |
| 858 | * Returns an object with field data |
| 859 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 860 | * @param string the table name |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 861 | * @return object |
| 862 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 863 | public function field_data($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 864 | { |
| 865 | if ($table == '') |
| 866 | { |
| 867 | if ($this->db_debug) |
| 868 | { |
| 869 | return $this->display_error('db_field_param_missing'); |
| 870 | } |
| 871 | return FALSE; |
| 872 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 873 | |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 874 | $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 875 | |
| 876 | return $query->field_data(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 877 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 878 | |
| 879 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 880 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 881 | /** |
| 882 | * Generate an insert string |
| 883 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 884 | * @param string the table upon which the query will be performed |
| 885 | * @param array an associative array data of key/values |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 886 | * @return string |
| 887 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 888 | public function insert_string($table, $data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 889 | { |
| 890 | $fields = array(); |
| 891 | $values = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 892 | |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 893 | foreach ($data as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 894 | { |
| 895 | $fields[] = $this->_escape_identifiers($key); |
| 896 | $values[] = $this->escape($val); |
| 897 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 898 | |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 899 | return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 900 | } |
| 901 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 902 | // -------------------------------------------------------------------- |
| 903 | |
| 904 | /** |
| 905 | * Generate an update string |
| 906 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 907 | * @param string the table upon which the query will be performed |
| 908 | * @param array an associative array data of key/values |
| 909 | * @param mixed the "where" statement |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 910 | * @return string |
| 911 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 912 | public function update_string($table, $data, $where) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 913 | { |
| 914 | if ($where == '') |
| 915 | { |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 916 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 917 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 918 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 919 | $fields = array(); |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 920 | foreach ($data as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 921 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 922 | $fields[$this->protect_identifiers($key)] = $this->escape($val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | if ( ! is_array($where)) |
| 926 | { |
| 927 | $dest = array($where); |
| 928 | } |
| 929 | else |
| 930 | { |
| 931 | $dest = array(); |
| 932 | foreach ($where as $key => $val) |
| 933 | { |
| 934 | $prefix = (count($dest) == 0) ? '' : ' AND '; |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 935 | $key = $this->protect_identifiers($key); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 936 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 937 | if ($val !== '') |
| 938 | { |
| 939 | if ( ! $this->_has_operator($key)) |
| 940 | { |
| 941 | $key .= ' ='; |
| 942 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 943 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 944 | $val = ' '.$this->escape($val); |
| 945 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 946 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 947 | $dest[] = $prefix.$key.$val; |
| 948 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 949 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 950 | |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 951 | return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 952 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 953 | |
| 954 | // -------------------------------------------------------------------- |
| 955 | |
| 956 | /** |
| 957 | * Tests whether the string has an SQL operator |
| 958 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 959 | * @param string |
| 960 | * @return bool |
| 961 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 962 | protected function _has_operator($str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 963 | { |
| 964 | $str = trim($str); |
| 965 | if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str)) |
| 966 | { |
| 967 | return FALSE; |
| 968 | } |
| 969 | |
| 970 | return TRUE; |
| 971 | } |
| 972 | |
| 973 | // -------------------------------------------------------------------- |
| 974 | |
| 975 | /** |
| 976 | * Enables a native PHP function to be run, using a platform agnostic wrapper. |
| 977 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 978 | * @param string the function name |
| 979 | * @param mixed any parameters needed by the function |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 980 | * @return mixed |
| 981 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 982 | public function call_function($function) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 983 | { |
| 984 | $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 985 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 986 | if (FALSE === strpos($driver, $function)) |
| 987 | { |
| 988 | $function = $driver.$function; |
| 989 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 990 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 991 | if ( ! function_exists($function)) |
| 992 | { |
| 993 | if ($this->db_debug) |
| 994 | { |
| 995 | return $this->display_error('db_unsupported_function'); |
| 996 | } |
| 997 | return FALSE; |
| 998 | } |
| 999 | else |
| 1000 | { |
| 1001 | $args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null; |
| 1002 | |
Repox | 71b7809 | 2011-12-01 09:19:43 +0100 | [diff] [blame] | 1003 | if (is_null($args)) |
| 1004 | { |
| 1005 | return call_user_func($function); |
| 1006 | } |
| 1007 | else |
| 1008 | { |
| 1009 | return call_user_func_array($function, $args); |
| 1010 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | // -------------------------------------------------------------------- |
| 1015 | |
| 1016 | /** |
| 1017 | * Set Cache Directory Path |
| 1018 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1019 | * @param string the path to the cache directory |
| 1020 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1021 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1022 | public function cache_set_path($path = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1023 | { |
| 1024 | $this->cachedir = $path; |
| 1025 | } |
| 1026 | |
| 1027 | // -------------------------------------------------------------------- |
| 1028 | |
| 1029 | /** |
| 1030 | * Enable Query Caching |
| 1031 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1032 | * @return bool cache_on value |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1033 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1034 | public function cache_on() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1035 | { |
| 1036 | $this->cache_on = TRUE; |
| 1037 | return TRUE; |
| 1038 | } |
| 1039 | |
| 1040 | // -------------------------------------------------------------------- |
| 1041 | |
| 1042 | /** |
| 1043 | * Disable Query Caching |
| 1044 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1045 | * @return bool cache_on value |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1046 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1047 | public function cache_off() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1048 | { |
| 1049 | $this->cache_on = FALSE; |
| 1050 | return FALSE; |
| 1051 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1052 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1053 | |
| 1054 | // -------------------------------------------------------------------- |
| 1055 | |
| 1056 | /** |
| 1057 | * Delete the cache files associated with a particular URI |
| 1058 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1059 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1060 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1061 | public function cache_delete($segment_one = '', $segment_two = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1062 | { |
| 1063 | if ( ! $this->_cache_init()) |
| 1064 | { |
| 1065 | return FALSE; |
| 1066 | } |
| 1067 | return $this->CACHE->delete($segment_one, $segment_two); |
| 1068 | } |
| 1069 | |
| 1070 | // -------------------------------------------------------------------- |
| 1071 | |
| 1072 | /** |
| 1073 | * Delete All cache files |
| 1074 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1075 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1076 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1077 | public function cache_delete_all() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1078 | { |
| 1079 | if ( ! $this->_cache_init()) |
| 1080 | { |
| 1081 | return FALSE; |
| 1082 | } |
| 1083 | |
| 1084 | return $this->CACHE->delete_all(); |
| 1085 | } |
| 1086 | |
| 1087 | // -------------------------------------------------------------------- |
| 1088 | |
| 1089 | /** |
| 1090 | * Initialize the Cache Class |
| 1091 | * |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1092 | * @return bool |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1093 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1094 | protected function _cache_init() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1095 | { |
| 1096 | if (is_object($this->CACHE) AND class_exists('CI_DB_Cache')) |
| 1097 | { |
| 1098 | return TRUE; |
| 1099 | } |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 1100 | |
| 1101 | if ( ! class_exists('CI_DB_Cache')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1102 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1103 | if ( ! @include(BASEPATH.'database/DB_cache.php')) |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 1104 | { |
| 1105 | return $this->cache_off(); |
| 1106 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1107 | } |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 1108 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1109 | $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects |
| 1110 | return TRUE; |
| 1111 | } |
| 1112 | |
| 1113 | // -------------------------------------------------------------------- |
| 1114 | |
| 1115 | /** |
| 1116 | * Close DB Connection |
| 1117 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1118 | * @return void |
| 1119 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1120 | public function close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1121 | { |
| 1122 | if (is_resource($this->conn_id) OR is_object($this->conn_id)) |
| 1123 | { |
| 1124 | $this->_close($this->conn_id); |
| 1125 | } |
| 1126 | $this->conn_id = FALSE; |
| 1127 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1128 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1129 | // -------------------------------------------------------------------- |
| 1130 | |
| 1131 | /** |
| 1132 | * Display an error message |
| 1133 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1134 | * @param string the error message |
| 1135 | * @param string any "swap" values |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1136 | * @param bool whether to localize the message |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1137 | * @return string sends the application/error_db.php template |
| 1138 | */ |
Timothy Warren | e45518d | 2012-03-06 07:38:00 -0500 | [diff] [blame] | 1139 | public function display_error($error = '', $swap = '', $native = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1140 | { |
Derek Jones | e779220 | 2010-03-02 17:24:46 -0600 | [diff] [blame] | 1141 | $LANG =& load_class('Lang', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1142 | $LANG->load('db'); |
| 1143 | |
| 1144 | $heading = $LANG->line('db_error_heading'); |
| 1145 | |
| 1146 | if ($native == TRUE) |
| 1147 | { |
Andrey Andreev | 85a99cc | 2011-09-24 17:17:37 +0300 | [diff] [blame] | 1148 | $message = (array) $error; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1149 | } |
| 1150 | else |
| 1151 | { |
| 1152 | $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; |
| 1153 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1154 | |
Pascal Kriete | 60f8c39 | 2010-08-25 18:03:28 +0200 | [diff] [blame] | 1155 | // Find the most likely culprit of the error by going through |
| 1156 | // the backtrace until the source file is no longer in the |
| 1157 | // database folder. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1158 | |
Pascal Kriete | 60f8c39 | 2010-08-25 18:03:28 +0200 | [diff] [blame] | 1159 | $trace = debug_backtrace(); |
| 1160 | |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 1161 | foreach ($trace as $call) |
Pascal Kriete | 60f8c39 | 2010-08-25 18:03:28 +0200 | [diff] [blame] | 1162 | { |
| 1163 | if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) |
| 1164 | { |
| 1165 | // Found it - use a relative path for safety |
| 1166 | $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); |
| 1167 | $message[] = 'Line Number: '.$call['line']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1168 | |
Pascal Kriete | 60f8c39 | 2010-08-25 18:03:28 +0200 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1172 | |
Derek Jones | e779220 | 2010-03-02 17:24:46 -0600 | [diff] [blame] | 1173 | $error =& load_class('Exceptions', 'core'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1174 | echo $error->show_error($heading, $message, 'error_db'); |
| 1175 | exit; |
| 1176 | } |
| 1177 | |
| 1178 | // -------------------------------------------------------------------- |
| 1179 | |
| 1180 | /** |
| 1181 | * Protect Identifiers |
| 1182 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1183 | * This function is used extensively by the Active Record class, and by |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1184 | * a couple functions in this class. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1185 | * It takes a column or table name (optionally with an alias) and inserts |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1186 | * the table prefix onto it. Some logic is necessary in order to deal with |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1187 | * column names that include the path. Consider a query like this: |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1188 | * |
| 1189 | * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table |
| 1190 | * |
| 1191 | * Or a query with aliasing: |
| 1192 | * |
| 1193 | * SELECT m.member_id, m.member_name FROM members AS m |
| 1194 | * |
| 1195 | * Since the column name can include up to four segments (host, DB, table, column) |
| 1196 | * or also have an alias prefix, we need to do a bit of work to figure this out and |
| 1197 | * insert the table prefix (if it exists) in the proper position, and escape only |
| 1198 | * the correct identifiers. |
| 1199 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1200 | * @param string |
| 1201 | * @param bool |
| 1202 | * @param mixed |
| 1203 | * @param bool |
| 1204 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1205 | */ |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 1206 | public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1207 | { |
| 1208 | if ( ! is_bool($protect_identifiers)) |
| 1209 | { |
| 1210 | $protect_identifiers = $this->_protect_identifiers; |
| 1211 | } |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 1212 | |
| 1213 | if (is_array($item)) |
| 1214 | { |
| 1215 | $escaped_array = array(); |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 1216 | foreach ($item as $k => $v) |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 1217 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 1218 | $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v); |
Derek Allard | e37ab38 | 2009-02-03 16:13:57 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | return $escaped_array; |
| 1222 | } |
| 1223 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1224 | // Convert tabs or multiple spaces into single spaces |
Derek Jones | 7b3b96c | 2009-02-10 21:01:47 +0000 | [diff] [blame] | 1225 | $item = preg_replace('/[\t ]+/', ' ', $item); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1226 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1227 | // If the item has an alias declaration we remove it and set it aside. |
| 1228 | // Basically we remove everything to the right of the first space |
| 1229 | $alias = ''; |
| 1230 | if (strpos($item, ' ') !== FALSE) |
Derek Allard | 911d3e0 | 2008-12-15 14:08:35 +0000 | [diff] [blame] | 1231 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1232 | $alias = strstr($item, " "); |
| 1233 | $item = substr($item, 0, - strlen($alias)); |
| 1234 | } |
| 1235 | |
Derek Allard | 911d3e0 | 2008-12-15 14:08:35 +0000 | [diff] [blame] | 1236 | // This is basically a bug fix for queries that use MAX, MIN, etc. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1237 | // If a parenthesis is found we know that we do not need to |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1238 | // escape the data or add a prefix. There's probably a more graceful |
Derek Allard | 911d3e0 | 2008-12-15 14:08:35 +0000 | [diff] [blame] | 1239 | // way to deal with this, but I'm not thinking of it -- Rick |
| 1240 | if (strpos($item, '(') !== FALSE) |
| 1241 | { |
| 1242 | return $item.$alias; |
| 1243 | } |
| 1244 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1245 | // Break the string apart if it contains periods, then insert the table prefix |
| 1246 | // in the correct location, assuming the period doesn't indicate that we're dealing |
| 1247 | // with an alias. While we're at it, we will escape the components |
| 1248 | if (strpos($item, '.') !== FALSE) |
| 1249 | { |
| 1250 | $parts = explode('.', $item); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1251 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1252 | // Does the first segment of the exploded item match |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1253 | // one of the aliases previously identified? If so, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1254 | // we have nothing more to do other than escape the item |
| 1255 | if (in_array($parts[0], $this->ar_aliased_tables)) |
Derek Allard | 911d3e0 | 2008-12-15 14:08:35 +0000 | [diff] [blame] | 1256 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1257 | if ($protect_identifiers === TRUE) |
| 1258 | { |
| 1259 | foreach ($parts as $key => $val) |
| 1260 | { |
| 1261 | if ( ! in_array($val, $this->_reserved_identifiers)) |
| 1262 | { |
| 1263 | $parts[$key] = $this->_escape_identifiers($val); |
| 1264 | } |
| 1265 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1266 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1267 | $item = implode('.', $parts); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1268 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1269 | return $item.$alias; |
| 1270 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1271 | |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1272 | // Is there a table prefix defined in the config file? If not, no need to do anything |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1273 | if ($this->dbprefix != '') |
| 1274 | { |
| 1275 | // We now add the table prefix based on some logic. |
| 1276 | // Do we have 4 segments (hostname.database.table.column)? |
| 1277 | // If so, we add the table prefix to the column name in the 3rd segment. |
| 1278 | if (isset($parts[3])) |
| 1279 | { |
| 1280 | $i = 2; |
| 1281 | } |
| 1282 | // Do we have 3 segments (database.table.column)? |
| 1283 | // If so, we add the table prefix to the column name in 2nd position |
| 1284 | elseif (isset($parts[2])) |
| 1285 | { |
| 1286 | $i = 1; |
| 1287 | } |
| 1288 | // Do we have 2 segments (table.column)? |
| 1289 | // If so, we add the table prefix to the column name in 1st segment |
| 1290 | else |
| 1291 | { |
| 1292 | $i = 0; |
| 1293 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1294 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1295 | // This flag is set when the supplied $item does not contain a field name. |
| 1296 | // This can happen when this function is being called from a JOIN. |
| 1297 | if ($field_exists == FALSE) |
| 1298 | { |
| 1299 | $i++; |
| 1300 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1301 | |
Derek Jones | 55acc8b | 2009-07-11 03:38:13 +0000 | [diff] [blame] | 1302 | // Verify table prefix and replace if necessary |
| 1303 | if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0) |
| 1304 | { |
| 1305 | $parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]); |
| 1306 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1307 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1308 | // We only add the table prefix if it does not already exist |
| 1309 | if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix) |
| 1310 | { |
| 1311 | $parts[$i] = $this->dbprefix.$parts[$i]; |
| 1312 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1313 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1314 | // Put the parts back together |
| 1315 | $item = implode('.', $parts); |
| 1316 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1317 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1318 | if ($protect_identifiers === TRUE) |
| 1319 | { |
| 1320 | $item = $this->_escape_identifiers($item); |
| 1321 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1322 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1323 | return $item.$alias; |
| 1324 | } |
| 1325 | |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1326 | // Is there a table prefix? If not, no need to insert it |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1327 | if ($this->dbprefix != '') |
| 1328 | { |
Derek Jones | 55acc8b | 2009-07-11 03:38:13 +0000 | [diff] [blame] | 1329 | // Verify table prefix and replace if necessary |
| 1330 | if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0) |
| 1331 | { |
| 1332 | $item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item); |
| 1333 | } |
| 1334 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1335 | // Do we prefix an item with no segments? |
| 1336 | if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix) |
| 1337 | { |
| 1338 | $item = $this->dbprefix.$item; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1339 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers)) |
| 1343 | { |
| 1344 | $item = $this->_escape_identifiers($item); |
| 1345 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1346 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1347 | return $item.$alias; |
| 1348 | } |
Andrey Andreev | 4c20260 | 2012-03-06 20:34:52 +0200 | [diff] [blame^] | 1349 | |
Túbal Martín | 511f225 | 2011-11-24 14:43:45 +0100 | [diff] [blame] | 1350 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1351 | |
Túbal Martín | 511f225 | 2011-11-24 14:43:45 +0100 | [diff] [blame] | 1352 | /** |
| 1353 | * Dummy method that allows Active Record class to be disabled |
| 1354 | * |
| 1355 | * This function is used extensively by every db driver. |
| 1356 | * |
Túbal Martín | 511f225 | 2011-11-24 14:43:45 +0100 | [diff] [blame] | 1357 | * @return void |
| 1358 | */ |
| 1359 | protected function _reset_select() |
| 1360 | { |
Túbal Martín | 511f225 | 2011-11-24 14:43:45 +0100 | [diff] [blame] | 1361 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1362 | |
| 1363 | } |
| 1364 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1365 | /* End of file DB_driver.php */ |
Timothy Warren | 6f531dc | 2011-10-10 10:10:46 -0400 | [diff] [blame] | 1366 | /* Location: ./system/database/DB_driver.php */ |