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