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