blob: 2daf8eaa053ce4d9f1ae5c8b9c3c4cb5e7ea754e [file] [log] [blame]
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevaf5d5582012-01-25 21:34:47 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevaf5d5582012-01-25 21:34:47 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * Database Driver Class
30 *
31 * This is the platform-independent base DB implementation class.
32 * This class will not be called directly. Rather, the adapter
33 * class for the specific database will extend and instantiate it.
34 *
35 * @package CodeIgniter
36 * @subpackage Drivers
37 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050038 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000039 * @link http://codeigniter.com/user_guide/database/
40 */
41class CI_DB_driver {
42
Andrey Andreev45ba4f72012-02-13 01:24:39 +020043 public $dsn;
Andrey Andreevaf5d5582012-01-25 21:34:47 +020044 public $username;
45 public $password;
46 public $hostname;
47 public $database;
48 public $dbdriver = 'mysql';
49 public $dbprefix = '';
50 public $char_set = 'utf8';
51 public $dbcollat = 'utf8_general_ci';
52 public $autoinit = TRUE; // Whether to automatically initialize the DB
53 public $swap_pre = '';
54 public $port = '';
55 public $pconnect = FALSE;
56 public $conn_id = FALSE;
57 public $result_id = FALSE;
58 public $db_debug = FALSE;
59 public $benchmark = 0;
60 public $query_count = 0;
61 public $bind_marker = '?';
62 public $save_queries = TRUE;
63 public $queries = array();
64 public $query_times = array();
65 public $data_cache = array();
66 public $trans_enabled = TRUE;
67 public $trans_strict = TRUE;
68 protected $_trans_depth = 0;
69 protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
70 public $cache_on = FALSE;
71 public $cachedir = '';
72 public $cache_autodel = FALSE;
73 public $CACHE; // The cache class object
Derek Allard2067d1a2008-11-13 22:59:24 +000074
Andrey Andreevaf5d5582012-01-25 21:34:47 +020075 protected $_protect_identifiers = TRUE;
76 protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
Derek Allard2067d1a2008-11-13 22:59:24 +000077
Andrey Andreevf32110a2012-01-26 11:04:11 +020078 // These are used with Oracle
Andrey Andreevaf5d5582012-01-25 21:34:47 +020079 public $stmt_id;
80 public $curs_id;
81 public $limit_used;
Barry Mienydd671972010-10-04 16:33:58 +020082
Derek Allard2067d1a2008-11-13 22:59:24 +000083 /**
Andrey Andreevaf5d5582012-01-25 21:34:47 +020084 * Constructor. Accepts one parameter containing the database
Derek Allard2067d1a2008-11-13 22:59:24 +000085 * connection settings.
86 *
87 * @param array
Barry Mienydd671972010-10-04 16:33:58 +020088 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +020089 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +000090 {
91 if (is_array($params))
92 {
93 foreach ($params as $key => $val)
94 {
95 $this->$key = $val;
96 }
97 }
98
99 log_message('debug', 'Database Driver Class Initialized');
100 }
Barry Mienydd671972010-10-04 16:33:58 +0200101
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 // --------------------------------------------------------------------
103
104 /**
105 * Initialize Database Settings
106 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200107 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200108 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200109 public function initialize()
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200111 /* If an established connection is available, then there's
112 * no need to connect and select the database.
113 *
114 * Depending on the database driver, conn_id can be either
115 * boolean TRUE, a resource or an object.
116 */
117 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 {
119 return TRUE;
120 }
Barry Mienydd671972010-10-04 16:33:58 +0200121
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200123
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 // Connect to the database and set the connection ID
125 $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
126
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200127 // No connection resource? Check if there is a failover else throw an error
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 if ( ! $this->conn_id)
129 {
Felix Balfoort5d581b62011-11-29 15:53:01 +0100130 // Check if there is a failover set
131 if ( ! empty($this->failover) && is_array($this->failover))
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
Felix Balfoort5d581b62011-11-29 15:53:01 +0100133 // Go over all the failovers
134 foreach ($this->failover as $failover)
135 {
136 // Replace the current settings with those of the failover
137 foreach ($failover as $key => $val)
138 {
139 $this->$key = $val;
140 }
141
142 // Try to connect
143 $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
144
145 // If a connection is made break the foreach loop
146 if ($this->conn_id)
147 {
148 break;
149 }
150 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 }
Felix Balfoort5d581b62011-11-29 15:53:01 +0100152
153 // We still don't have a connection?
154 if ( ! $this->conn_id)
155 {
156 log_message('error', 'Unable to connect to the database');
157
158 if ($this->db_debug)
159 {
160 $this->display_error('db_unable_to_connect');
161 }
162 return FALSE;
163 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 }
165
166 // ----------------------------------------------------------------
167
168 // Select the DB... assuming a database name is specified in the config file
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200169 if ($this->database !== '' && ! $this->db_select())
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 {
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200171 log_message('error', 'Unable to select database: '.$this->database);
Barry Mienydd671972010-10-04 16:33:58 +0200172
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200173 if ($this->db_debug)
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 {
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200175 $this->display_error('db_unable_to_select', $this->database);
Derek Allard2067d1a2008-11-13 22:59:24 +0000176 }
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200177 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 }
179
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200180 // Now we set the character set and that's all
181 return $this->db_set_charset($this->char_set, $this->dbcollat);
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 }
Barry Mienydd671972010-10-04 16:33:58 +0200183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 // --------------------------------------------------------------------
185
186 /**
187 * Set client character set
188 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 * @param string
190 * @param string
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200191 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 */
Andrey Andreev063f5962012-02-27 12:20:52 +0200193 public function db_set_charset($charset, $collation = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200195 if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset, $collation))
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200197 log_message('error', 'Unable to set database connection charset: '.$charset);
Barry Mienydd671972010-10-04 16:33:58 +0200198
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 if ($this->db_debug)
200 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200201 $this->display_error('db_unable_to_set_charset', $charset);
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 }
Barry Mienydd671972010-10-04 16:33:58 +0200203
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 return FALSE;
205 }
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 return TRUE;
208 }
Barry Mienydd671972010-10-04 16:33:58 +0200209
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 // --------------------------------------------------------------------
211
212 /**
213 * The name of the platform in use (mysql, mssql, etc...)
214 *
Barry Mienydd671972010-10-04 16:33:58 +0200215 * @return string
216 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200217 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 {
219 return $this->dbdriver;
220 }
221
222 // --------------------------------------------------------------------
223
224 /**
Andrey Andreev08856b82012-03-03 03:19:28 +0200225 * Database version number
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 *
Andrey Andreev08856b82012-03-03 03:19:28 +0200227 * Returns a string containing the version of the database being used.
228 * Most drivers will override this method.
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 *
Barry Mienydd671972010-10-04 16:33:58 +0200230 * @return string
231 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200232 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200234 if (isset($this->data_cache['version']))
235 {
236 return $this->data_cache['version'];
237 }
238
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 if (FALSE === ($sql = $this->_version()))
240 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200241 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 }
Derek Allard3683f772009-12-16 17:32:33 +0000243
Andrey Andreev08856b82012-03-03 03:19:28 +0200244 $query = $this->query($sql);
245 $query = $query->row();
246 return $this->data_cache['version'] = $query->ver;
247 }
Derek Allard3683f772009-12-16 17:32:33 +0000248
Andrey Andreev08856b82012-03-03 03:19:28 +0200249 // --------------------------------------------------------------------
250
251 /**
252 * Version number query string
253 *
254 * @return string
255 */
256 protected function _version()
257 {
258 return 'SELECT VERSION() AS ver';
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 }
Barry Mienydd671972010-10-04 16:33:58 +0200260
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 // --------------------------------------------------------------------
262
263 /**
264 * Execute the query
265 *
266 * Accepts an SQL string as input and returns a result object upon
Derek Jones37f4b9c2011-07-01 17:56:50 -0500267 * successful execution of a "read" type query. Returns boolean TRUE
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 * upon successful execution of a "write" type query. Returns boolean
269 * FALSE upon failure, and if the $db_debug variable is set to TRUE
270 * will raise an error.
271 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 * @param string An SQL query string
273 * @param array An array of binding data
Barry Mienydd671972010-10-04 16:33:58 +0200274 * @return mixed
275 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200276 public function query($sql, $binds = FALSE, $return_object = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 {
278 if ($sql == '')
279 {
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200280 log_message('error', 'Invalid query: '.$sql);
281
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200282 return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 }
284
285 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200286 if ( ($this->dbprefix != '' && $this->swap_pre != '') && ($this->dbprefix != $this->swap_pre) )
Derek Jonese7792202010-03-02 17:24:46 -0600287 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200288 $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 }
Derek Jonese7792202010-03-02 17:24:46 -0600290
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200291 // Is query caching enabled? If the query is a "read type"
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 // we will load the caching class and return the previously
293 // cached query if it exists
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200294 if ($this->cache_on == TRUE && stripos($sql, 'SELECT') !== FALSE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200296 $this->load_rdriver();
297 if (FALSE !== ($cache = $this->CACHE->read($sql)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200299 return $cache;
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 }
301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 // Compile binds if needed
304 if ($binds !== FALSE)
305 {
306 $sql = $this->compile_binds($sql, $binds);
307 }
308
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200309 // Save the query for debugging
Derek Allard2067d1a2008-11-13 22:59:24 +0000310 if ($this->save_queries == TRUE)
311 {
312 $this->queries[] = $sql;
313 }
Barry Mienydd671972010-10-04 16:33:58 +0200314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 // Start the Query Timer
316 $time_start = list($sm, $ss) = explode(' ', microtime());
Barry Mienydd671972010-10-04 16:33:58 +0200317
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 // Run the Query
319 if (FALSE === ($this->result_id = $this->simple_query($sql)))
320 {
321 if ($this->save_queries == TRUE)
322 {
323 $this->query_times[] = 0;
324 }
Barry Mienydd671972010-10-04 16:33:58 +0200325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 // This will trigger a rollback if transactions are being used
327 $this->_trans_status = FALSE;
328
Andrey Andreev4be5de12012-03-02 15:45:41 +0200329 // Grab the error now, as we might run some additional queries before displaying the error
330 $error = $this->error();
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200331
332 // Log errors
Andrey Andreev4be5de12012-03-02 15:45:41 +0200333 log_message('error', 'Query error: '.$error['message']);
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200334
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 if ($this->db_debug)
336 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 // We call this function in order to roll-back queries
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200338 // if transactions are enabled. If we don't call this here
Barry Mienydd671972010-10-04 16:33:58 +0200339 // the error message will trigger an exit, causing the
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 // transactions to remain in limbo.
341 $this->trans_complete();
342
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200343 // Display errors
Andrey Andreev27984582012-03-03 04:43:10 +0200344 return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql));
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 }
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 return FALSE;
348 }
Barry Mienydd671972010-10-04 16:33:58 +0200349
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 // Stop and aggregate the query time results
351 $time_end = list($em, $es) = explode(' ', microtime());
352 $this->benchmark += ($em + $es) - ($sm + $ss);
353
354 if ($this->save_queries == TRUE)
355 {
356 $this->query_times[] = ($em + $es) - ($sm + $ss);
357 }
Barry Mienydd671972010-10-04 16:33:58 +0200358
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 // Increment the query counter
360 $this->query_count++;
Barry Mienydd671972010-10-04 16:33:58 +0200361
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 // Was the query a "write" type?
363 // If so we'll simply return true
364 if ($this->is_write_type($sql) === TRUE)
365 {
366 // If caching is enabled we'll auto-cleanup any
367 // existing files related to this particular URI
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200368 if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 {
370 $this->CACHE->delete();
371 }
Barry Mienydd671972010-10-04 16:33:58 +0200372
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 return TRUE;
374 }
Barry Mienydd671972010-10-04 16:33:58 +0200375
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 // Return TRUE if we don't need to create a result object
377 // Currently only the Oracle driver uses this when stored
378 // procedures are used
379 if ($return_object !== TRUE)
380 {
381 return TRUE;
382 }
Barry Mienydd671972010-10-04 16:33:58 +0200383
384 // Load and instantiate the result driver
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200385 $driver = $this->load_rdriver();
386 $RES = new $driver();
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 $RES->conn_id = $this->conn_id;
388 $RES->result_id = $this->result_id;
389
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200390 if ($this->dbdriver === 'oci8')
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 {
392 $RES->stmt_id = $this->stmt_id;
Andrey Andreeva5f2f692012-01-25 21:44:56 +0200393 $RES->curs_id = $this->curs_id;
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 $RES->limit_used = $this->limit_used;
395 $this->stmt_id = FALSE;
396 }
Barry Mienydd671972010-10-04 16:33:58 +0200397
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 // oci8 vars must be set before calling this
399 $RES->num_rows = $RES->num_rows();
Barry Mienydd671972010-10-04 16:33:58 +0200400
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200401 // Is query caching enabled? If so, we'll serialize the
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 // result object and save it to a cache file.
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200403 if ($this->cache_on == TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 {
405 // We'll create a new instance of the result object
406 // only without the platform specific driver since
407 // we can't use it with cached data (the query result
408 // resource ID won't be any good once we've cached the
409 // result object, so we'll have to compile the data
410 // and save it)
411 $CR = new CI_DB_result();
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 $CR->result_object = $RES->result_object();
413 $CR->result_array = $RES->result_array();
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200414 $CR->num_rows = $RES->num_rows();
Barry Mienydd671972010-10-04 16:33:58 +0200415
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 // Reset these since cached objects can not utilize resource IDs.
417 $CR->conn_id = NULL;
418 $CR->result_id = NULL;
419
420 $this->CACHE->write($sql, $CR);
421 }
Barry Mienydd671972010-10-04 16:33:58 +0200422
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 return $RES;
424 }
425
426 // --------------------------------------------------------------------
427
428 /**
429 * Load the result drivers
430 *
Barry Mienydd671972010-10-04 16:33:58 +0200431 * @return string the name of the result class
432 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200433 public function load_rdriver()
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 {
435 $driver = 'CI_DB_'.$this->dbdriver.'_result';
436
437 if ( ! class_exists($driver))
438 {
Greg Aker3a746652011-04-19 10:59:47 -0500439 include_once(BASEPATH.'database/DB_result.php');
440 include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 }
Barry Mienydd671972010-10-04 16:33:58 +0200442
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 return $driver;
444 }
Barry Mienydd671972010-10-04 16:33:58 +0200445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 // --------------------------------------------------------------------
447
448 /**
449 * Simple Query
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200450 * This is a simplified version of the query() function. Internally
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * we only use it when running transaction commands since they do
452 * not require all the features of the main query() function.
453 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 * @param string the sql query
Barry Mienydd671972010-10-04 16:33:58 +0200455 * @return mixed
456 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200457 public function simple_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 {
459 if ( ! $this->conn_id)
460 {
461 $this->initialize();
462 }
463
464 return $this->_execute($sql);
465 }
Barry Mienydd671972010-10-04 16:33:58 +0200466
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 // --------------------------------------------------------------------
468
469 /**
470 * Disable Transactions
471 * This permits transactions to be disabled at run-time.
472 *
Barry Mienydd671972010-10-04 16:33:58 +0200473 * @return void
474 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200475 public function trans_off()
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 {
477 $this->trans_enabled = FALSE;
478 }
479
480 // --------------------------------------------------------------------
481
482 /**
483 * Enable/disable Transaction Strict Mode
484 * When strict mode is enabled, if you are running multiple groups of
485 * transactions, if one group fails all groups will be rolled back.
486 * If strict mode is disabled, each group is treated autonomously, meaning
487 * a failure of one group will not affect any others
488 *
Barry Mienydd671972010-10-04 16:33:58 +0200489 * @return void
490 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200491 public function trans_strict($mode = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 {
493 $this->trans_strict = is_bool($mode) ? $mode : TRUE;
494 }
Barry Mienydd671972010-10-04 16:33:58 +0200495
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 // --------------------------------------------------------------------
497
498 /**
499 * Start Transaction
500 *
Barry Mienydd671972010-10-04 16:33:58 +0200501 * @return void
502 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200503 public function trans_start($test_mode = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200504 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 if ( ! $this->trans_enabled)
506 {
507 return FALSE;
508 }
509
510 // When transactions are nested we only begin/commit/rollback the outermost ones
511 if ($this->_trans_depth > 0)
512 {
513 $this->_trans_depth += 1;
514 return;
515 }
Barry Mienydd671972010-10-04 16:33:58 +0200516
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 $this->trans_begin($test_mode);
Jacob Terry07fcedf2011-11-22 11:21:36 -0500518 $this->_trans_depth += 1;
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 }
520
521 // --------------------------------------------------------------------
522
523 /**
524 * Complete Transaction
525 *
Barry Mienydd671972010-10-04 16:33:58 +0200526 * @return bool
527 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200528 public function trans_complete()
Derek Allard2067d1a2008-11-13 22:59:24 +0000529 {
530 if ( ! $this->trans_enabled)
531 {
532 return FALSE;
533 }
Barry Mienydd671972010-10-04 16:33:58 +0200534
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 // When transactions are nested we only begin/commit/rollback the outermost ones
536 if ($this->_trans_depth > 1)
537 {
538 $this->_trans_depth -= 1;
539 return TRUE;
540 }
Jacob Terry07fcedf2011-11-22 11:21:36 -0500541 else
542 {
543 $this->_trans_depth = 0;
544 }
Barry Mienydd671972010-10-04 16:33:58 +0200545
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 // The query() function will set this flag to FALSE in the event that a query failed
547 if ($this->_trans_status === FALSE)
548 {
549 $this->trans_rollback();
Barry Mienydd671972010-10-04 16:33:58 +0200550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 // If we are NOT running in strict mode, we will reset
552 // the _trans_status flag so that subsequent groups of transactions
553 // will be permitted.
554 if ($this->trans_strict === FALSE)
555 {
556 $this->_trans_status = TRUE;
557 }
558
559 log_message('debug', 'DB Transaction Failure');
560 return FALSE;
561 }
Barry Mienydd671972010-10-04 16:33:58 +0200562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 $this->trans_commit();
564 return TRUE;
565 }
566
567 // --------------------------------------------------------------------
568
569 /**
570 * Lets you retrieve the transaction flag to determine if it has failed
571 *
Barry Mienydd671972010-10-04 16:33:58 +0200572 * @return bool
573 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200574 public function trans_status()
Derek Allard2067d1a2008-11-13 22:59:24 +0000575 {
576 return $this->_trans_status;
577 }
578
579 // --------------------------------------------------------------------
580
581 /**
582 * Compile Bindings
583 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 * @param string the sql statement
585 * @param array an array of bind data
Barry Mienydd671972010-10-04 16:33:58 +0200586 * @return string
587 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200588 public function compile_binds($sql, $binds)
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 {
590 if (strpos($sql, $this->bind_marker) === FALSE)
591 {
592 return $sql;
593 }
Barry Mienydd671972010-10-04 16:33:58 +0200594
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 if ( ! is_array($binds))
596 {
597 $binds = array($binds);
598 }
Barry Mienydd671972010-10-04 16:33:58 +0200599
Derek Allard2067d1a2008-11-13 22:59:24 +0000600 // Get the sql segments around the bind markers
601 $segments = explode($this->bind_marker, $sql);
602
603 // The count of bind should be 1 less then the count of segments
604 // If there are more bind arguments trim it down
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200605 if (count($binds) >= count($segments))
606 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000607 $binds = array_slice($binds, 0, count($segments)-1);
608 }
609
610 // Construct the binded query
611 $result = $segments[0];
612 $i = 0;
613 foreach ($binds as $bind)
614 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200615 $result .= $this->escape($bind).$segments[++$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 }
617
618 return $result;
619 }
Barry Mienydd671972010-10-04 16:33:58 +0200620
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 // --------------------------------------------------------------------
622
623 /**
624 * Determines if a query is a "write" type.
625 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000626 * @param string An SQL query string
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200627 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200628 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200629 public function is_write_type($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000630 {
Andrey Andreev5fa72982012-03-03 04:13:20 +0200631 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 Allard2067d1a2008-11-13 22:59:24 +0000632 }
Barry Mienydd671972010-10-04 16:33:58 +0200633
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 // --------------------------------------------------------------------
635
636 /**
637 * Calculate the aggregate query elapsed time
638 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200639 * @param int The number of decimal places
640 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200641 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200642 public function elapsed_time($decimals = 6)
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 {
644 return number_format($this->benchmark, $decimals);
645 }
Barry Mienydd671972010-10-04 16:33:58 +0200646
Derek Allard2067d1a2008-11-13 22:59:24 +0000647 // --------------------------------------------------------------------
648
649 /**
650 * Returns the total number of queries
651 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200652 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200653 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200654 public function total_queries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000655 {
656 return $this->query_count;
657 }
Barry Mienydd671972010-10-04 16:33:58 +0200658
Derek Allard2067d1a2008-11-13 22:59:24 +0000659 // --------------------------------------------------------------------
660
661 /**
662 * Returns the last query that was executed
663 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200664 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200665 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200666 public function last_query()
Derek Allard2067d1a2008-11-13 22:59:24 +0000667 {
668 return end($this->queries);
669 }
670
671 // --------------------------------------------------------------------
672
673 /**
674 * "Smart" Escape String
675 *
676 * Escapes data based on type
677 * Sets boolean and null types
678 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000679 * @param string
Barry Mienydd671972010-10-04 16:33:58 +0200680 * @return mixed
681 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200682 public function escape($str)
Barry Mienydd671972010-10-04 16:33:58 +0200683 {
Derek Jonesa377bdd2009-02-11 18:55:24 +0000684 if (is_string($str))
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200686 return "'".$this->escape_str($str)."'";
Derek Jonesa377bdd2009-02-11 18:55:24 +0000687 }
688 elseif (is_bool($str))
689 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200690 return ($str === FALSE) ? 0 : 1;
Derek Jonesa377bdd2009-02-11 18:55:24 +0000691 }
692 elseif (is_null($str))
693 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200694 return 'NULL';
Derek Jonesa377bdd2009-02-11 18:55:24 +0000695 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000696
697 return $str;
698 }
699
700 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600701
Derek Jonese4ed5832009-02-20 21:44:59 +0000702 /**
Derek Jonesbdc7fb92009-02-20 21:55:10 +0000703 * Escape LIKE String
Derek Jonese4ed5832009-02-20 21:44:59 +0000704 *
705 * Calls the individual driver for platform
706 * specific escaping for LIKE conditions
Barry Mienydd671972010-10-04 16:33:58 +0200707 *
Derek Jonese4ed5832009-02-20 21:44:59 +0000708 * @param string
709 * @return mixed
710 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200711 public function escape_like_str($str)
Barry Mienydd671972010-10-04 16:33:58 +0200712 {
713 return $this->escape_str($str, TRUE);
Derek Jonese4ed5832009-02-20 21:44:59 +0000714 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000715
Derek Jonese4ed5832009-02-20 21:44:59 +0000716 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600717
Derek Allard2067d1a2008-11-13 22:59:24 +0000718 /**
719 * Primary
720 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200721 * Retrieves the primary key. It assumes that the row in the first
Derek Allard2067d1a2008-11-13 22:59:24 +0000722 * position is the primary key
723 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000724 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200725 * @return string
726 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200727 public function primary($table = '')
Barry Mienydd671972010-10-04 16:33:58 +0200728 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000729 $fields = $this->list_fields($table);
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200730 return is_array($fields) ? current($fields) : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000731 }
732
733 // --------------------------------------------------------------------
734
735 /**
736 * Returns an array of table names
737 *
Barry Mienydd671972010-10-04 16:33:58 +0200738 * @return array
739 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200740 public function list_tables($constrain_by_prefix = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000741 {
742 // Is there a cached result?
743 if (isset($this->data_cache['table_names']))
744 {
745 return $this->data_cache['table_names'];
746 }
Barry Mienydd671972010-10-04 16:33:58 +0200747
Derek Allard2067d1a2008-11-13 22:59:24 +0000748 if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix)))
749 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200750 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000751 }
752
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200753 $this->data_cache['table_names'] = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000754 $query = $this->query($sql);
Barry Mienydd671972010-10-04 16:33:58 +0200755
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200756 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000757 {
Andrey Andreev12567e82012-01-25 22:50:33 +0200758 // Do we know from which column to get the table name?
759 if ( ! isset($key))
760 {
761 if (array_key_exists('table_name', $row))
762 {
763 $key = 'table_name';
764 }
765 elseif (array_key_exists('TABLE_NAME', $row))
766 {
767 $key = 'TABLE_NAME';
768 }
769 else
770 {
771 /* We have no other choice but to just get the first element's key.
772 * Due to array_shift() accepting it's argument by reference, if
773 * E_STRICT is on, this would trigger a warning. So we'll have to
774 * assign it first.
775 */
776 $key = array_keys($row);
777 $key = array_shift($key);
778 }
779 }
780
781 $this->data_cache['table_names'][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000782 }
783
Derek Allard2067d1a2008-11-13 22:59:24 +0000784 return $this->data_cache['table_names'];
785 }
Barry Mienydd671972010-10-04 16:33:58 +0200786
Derek Allard2067d1a2008-11-13 22:59:24 +0000787 // --------------------------------------------------------------------
788
789 /**
790 * Determine if a particular table exists
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200791 *
792 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000793 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200794 public function table_exists($table_name)
Barry Mienydd671972010-10-04 16:33:58 +0200795 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200796 return in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables());
Derek Allard2067d1a2008-11-13 22:59:24 +0000797 }
Barry Mienydd671972010-10-04 16:33:58 +0200798
Derek Allard2067d1a2008-11-13 22:59:24 +0000799 // --------------------------------------------------------------------
800
801 /**
802 * Fetch MySQL Field Names
803 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000804 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200805 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000806 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200807 public function list_fields($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000808 {
809 // Is there a cached result?
810 if (isset($this->data_cache['field_names'][$table]))
811 {
812 return $this->data_cache['field_names'][$table];
813 }
Barry Mienydd671972010-10-04 16:33:58 +0200814
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 if ($table == '')
816 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200817 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000818 }
Barry Mienydd671972010-10-04 16:33:58 +0200819
Greg Aker1edde302010-01-26 00:17:01 +0000820 if (FALSE === ($sql = $this->_list_columns($table)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000821 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200822 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000823 }
Barry Mienydd671972010-10-04 16:33:58 +0200824
Derek Allard2067d1a2008-11-13 22:59:24 +0000825 $query = $this->query($sql);
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200826 $this->data_cache['field_names'][$table] = array();
Barry Mienydd671972010-10-04 16:33:58 +0200827
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500828 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000829 {
Andrey Andreev12567e82012-01-25 22:50:33 +0200830 // Do we know from where to get the column's name?
831 if ( ! isset($key))
832 {
833 if (array_key_exists('column_name', $row))
834 {
835 $key = 'column_name';
836 }
837 elseif (array_key_exists('COLUMN_NAME', $row))
838 {
839 $key = 'COLUMN_NAME';
840 }
841 else
842 {
843 /* We have no other choice but to just get the first element's key.
844 * Due to array_shift() accepting it's argument by reference, if
845 * E_STRICT is on, this would trigger a warning. So we'll have to
846 * assign it first.
847 */
848 $key = array_keys($row);
849 $key = array_shift($key);
850 }
851 }
852
853 $this->data_cache['field_names'][$table][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000854 }
Barry Mienydd671972010-10-04 16:33:58 +0200855
Derek Allard2067d1a2008-11-13 22:59:24 +0000856 return $this->data_cache['field_names'][$table];
857 }
858
859 // --------------------------------------------------------------------
860
861 /**
862 * Determine if a particular field exists
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200863 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000864 * @param string
865 * @param string
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200866 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000867 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200868 public function field_exists($field_name, $table_name)
Barry Mienydd671972010-10-04 16:33:58 +0200869 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200870 return in_array($field_name, $this->list_fields($table_name));
Derek Allard2067d1a2008-11-13 22:59:24 +0000871 }
Barry Mienydd671972010-10-04 16:33:58 +0200872
Derek Allard2067d1a2008-11-13 22:59:24 +0000873 // --------------------------------------------------------------------
874
875 /**
876 * Returns an object with field data
877 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000878 * @param string the table name
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200879 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200880 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200881 public function field_data($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000882 {
883 if ($table == '')
884 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200885 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000886 }
Barry Mienydd671972010-10-04 16:33:58 +0200887
Derek Allard2067d1a2008-11-13 22:59:24 +0000888 $query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE)));
Derek Allard2067d1a2008-11-13 22:59:24 +0000889 return $query->field_data();
Barry Mienydd671972010-10-04 16:33:58 +0200890 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000891
892 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200893
Derek Allard2067d1a2008-11-13 22:59:24 +0000894 /**
895 * Generate an insert string
896 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000897 * @param string the table upon which the query will be performed
898 * @param array an associative array data of key/values
Barry Mienydd671972010-10-04 16:33:58 +0200899 * @return string
900 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200901 public function insert_string($table, $data)
Derek Allard2067d1a2008-11-13 22:59:24 +0000902 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200903 $fields = $values = array();
Barry Mienydd671972010-10-04 16:33:58 +0200904
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500905 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000906 {
907 $fields[] = $this->_escape_identifiers($key);
908 $values[] = $this->escape($val);
909 }
Barry Mienydd671972010-10-04 16:33:58 +0200910
Derek Allard2067d1a2008-11-13 22:59:24 +0000911 return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
Barry Mienydd671972010-10-04 16:33:58 +0200912 }
913
Derek Allard2067d1a2008-11-13 22:59:24 +0000914 // --------------------------------------------------------------------
915
916 /**
917 * Generate an update string
918 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000919 * @param string the table upon which the query will be performed
920 * @param array an associative array data of key/values
921 * @param mixed the "where" statement
Barry Mienydd671972010-10-04 16:33:58 +0200922 * @return string
923 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200924 public function update_string($table, $data, $where)
Derek Allard2067d1a2008-11-13 22:59:24 +0000925 {
926 if ($where == '')
927 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200928 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000929 }
Barry Mienydd671972010-10-04 16:33:58 +0200930
Derek Allard2067d1a2008-11-13 22:59:24 +0000931 $fields = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500932 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 {
934 $fields[$this->_protect_identifiers($key)] = $this->escape($val);
935 }
936
937 if ( ! is_array($where))
938 {
939 $dest = array($where);
940 }
941 else
942 {
943 $dest = array();
944 foreach ($where as $key => $val)
945 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200946 $prefix = (count($dest) === 0) ? '' : ' AND ';
Andrey Andreevdc46d992011-09-24 16:25:23 +0300947 $key = $this->_protect_identifiers($key);
Barry Mienydd671972010-10-04 16:33:58 +0200948
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 if ($val !== '')
950 {
951 if ( ! $this->_has_operator($key))
952 {
953 $key .= ' =';
954 }
Barry Mienydd671972010-10-04 16:33:58 +0200955
Derek Allard2067d1a2008-11-13 22:59:24 +0000956 $val = ' '.$this->escape($val);
957 }
Barry Mienydd671972010-10-04 16:33:58 +0200958
Derek Allard2067d1a2008-11-13 22:59:24 +0000959 $dest[] = $prefix.$key.$val;
960 }
Barry Mienydd671972010-10-04 16:33:58 +0200961 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000962
963 return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
Barry Mienydd671972010-10-04 16:33:58 +0200964 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000965
966 // --------------------------------------------------------------------
967
968 /**
969 * Tests whether the string has an SQL operator
970 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 * @param string
972 * @return bool
973 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200974 protected function _has_operator($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000975 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200976 return (bool) preg_match('/(\s|<|>|!|=|is null|is not null)/i', trim($str));
Derek Allard2067d1a2008-11-13 22:59:24 +0000977 }
978
979 // --------------------------------------------------------------------
980
981 /**
982 * Enables a native PHP function to be run, using a platform agnostic wrapper.
983 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000984 * @param string the function name
985 * @param mixed any parameters needed by the function
Barry Mienydd671972010-10-04 16:33:58 +0200986 * @return mixed
987 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200988 public function call_function($function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000989 {
990 $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
Barry Mienydd671972010-10-04 16:33:58 +0200991
Derek Allard2067d1a2008-11-13 22:59:24 +0000992 if (FALSE === strpos($driver, $function))
993 {
994 $function = $driver.$function;
995 }
Barry Mienydd671972010-10-04 16:33:58 +0200996
Derek Allard2067d1a2008-11-13 22:59:24 +0000997 if ( ! function_exists($function))
998 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200999 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001000 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001001
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001002 return (func_num_args() > 1)
1003 ? call_user_func_array($function, array_splice(func_get_args(), 1))
1004 : call_user_func($function);
Derek Allard2067d1a2008-11-13 22:59:24 +00001005 }
1006
1007 // --------------------------------------------------------------------
1008
1009 /**
1010 * Set Cache Directory Path
1011 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001012 * @param string the path to the cache directory
1013 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001014 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001015 public function cache_set_path($path = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001016 {
1017 $this->cachedir = $path;
1018 }
1019
1020 // --------------------------------------------------------------------
1021
1022 /**
1023 * Enable Query Caching
1024 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001025 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001026 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001027 public function cache_on()
Derek Allard2067d1a2008-11-13 22:59:24 +00001028 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001029 return $this->cache_on = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 }
1031
1032 // --------------------------------------------------------------------
1033
1034 /**
1035 * Disable Query Caching
1036 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001037 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001038 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001039 public function cache_off()
Derek Allard2067d1a2008-11-13 22:59:24 +00001040 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001041 return $this->cache_on = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001042 }
Barry Mienydd671972010-10-04 16:33:58 +02001043
Derek Allard2067d1a2008-11-13 22:59:24 +00001044
1045 // --------------------------------------------------------------------
1046
1047 /**
1048 * Delete the cache files associated with a particular URI
1049 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001050 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001051 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001052 public function cache_delete($segment_one = '', $segment_two = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001053 {
1054 if ( ! $this->_cache_init())
1055 {
1056 return FALSE;
1057 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001058
Derek Allard2067d1a2008-11-13 22:59:24 +00001059 return $this->CACHE->delete($segment_one, $segment_two);
1060 }
1061
1062 // --------------------------------------------------------------------
1063
1064 /**
1065 * Delete All cache files
1066 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001067 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001068 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001069 public function cache_delete_all()
Derek Allard2067d1a2008-11-13 22:59:24 +00001070 {
1071 if ( ! $this->_cache_init())
1072 {
1073 return FALSE;
1074 }
1075
1076 return $this->CACHE->delete_all();
1077 }
1078
1079 // --------------------------------------------------------------------
1080
1081 /**
1082 * Initialize the Cache Class
1083 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001084 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001085 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001086 protected function _cache_init()
Derek Allard2067d1a2008-11-13 22:59:24 +00001087 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001088 if (class_exists('CI_DB_Cache'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001089 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001090 if (is_object($this->CACHE))
Derek Allarde37ab382009-02-03 16:13:57 +00001091 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001092 return TRUE;
Derek Allarde37ab382009-02-03 16:13:57 +00001093 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001094 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001095 elseif ( ! @include_once(BASEPATH.'database/DB_cache.php'))
1096 {
1097 return $this->cache_off();
1098 }
Derek Allarde37ab382009-02-03 16:13:57 +00001099
Derek Allard2067d1a2008-11-13 22:59:24 +00001100 $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
1101 return TRUE;
1102 }
1103
1104 // --------------------------------------------------------------------
1105
1106 /**
1107 * Close DB Connection
1108 *
Barry Mienydd671972010-10-04 16:33:58 +02001109 * @return void
1110 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001111 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +00001112 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001113 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +00001114 {
1115 $this->_close($this->conn_id);
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001116 $this->conn_id = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001117 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001118 }
Barry Mienydd671972010-10-04 16:33:58 +02001119
Derek Allard2067d1a2008-11-13 22:59:24 +00001120 // --------------------------------------------------------------------
1121
1122 /**
1123 * Display an error message
1124 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001125 * @param string the error message
1126 * @param string any "swap" values
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001127 * @param bool whether to localize the message
Barry Mienydd671972010-10-04 16:33:58 +02001128 * @return string sends the application/error_db.php template
1129 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001130 public function display_error($error = '', $swap = '', $native = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001131 {
Derek Jonese7792202010-03-02 17:24:46 -06001132 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001133 $LANG->load('db');
1134
1135 $heading = $LANG->line('db_error_heading');
1136
1137 if ($native == TRUE)
1138 {
Andrey Andreev85a99cc2011-09-24 17:17:37 +03001139 $message = (array) $error;
Derek Allard2067d1a2008-11-13 22:59:24 +00001140 }
1141 else
1142 {
1143 $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
1144 }
Barry Mienydd671972010-10-04 16:33:58 +02001145
Pascal Kriete60f8c392010-08-25 18:03:28 +02001146 // Find the most likely culprit of the error by going through
1147 // the backtrace until the source file is no longer in the
1148 // database folder.
Pascal Kriete60f8c392010-08-25 18:03:28 +02001149 $trace = debug_backtrace();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001150 foreach ($trace as $call)
Pascal Kriete60f8c392010-08-25 18:03:28 +02001151 {
1152 if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
1153 {
1154 // Found it - use a relative path for safety
1155 $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
1156 $message[] = 'Line Number: '.$call['line'];
Pascal Kriete60f8c392010-08-25 18:03:28 +02001157 break;
1158 }
1159 }
Barry Mienydd671972010-10-04 16:33:58 +02001160
Derek Jonese7792202010-03-02 17:24:46 -06001161 $error =& load_class('Exceptions', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001162 echo $error->show_error($heading, $message, 'error_db');
1163 exit;
1164 }
1165
1166 // --------------------------------------------------------------------
1167
1168 /**
1169 * Protect Identifiers
1170 *
1171 * This function adds backticks if appropriate based on db type
1172 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001173 * @param mixed the item to escape
1174 * @return mixed the item with backticks
1175 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001176 public function protect_identifiers($item, $prefix_single = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001177 {
1178 return $this->_protect_identifiers($item, $prefix_single);
1179 }
1180
1181 // --------------------------------------------------------------------
1182
1183 /**
1184 * Protect Identifiers
1185 *
1186 * This function is used extensively by the Active Record class, and by
Barry Mienydd671972010-10-04 16:33:58 +02001187 * a couple functions in this class.
Derek Allard2067d1a2008-11-13 22:59:24 +00001188 * It takes a column or table name (optionally with an alias) and inserts
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001189 * the table prefix onto it. Some logic is necessary in order to deal with
1190 * column names that include the path. Consider a query like this:
Derek Allard2067d1a2008-11-13 22:59:24 +00001191 *
1192 * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
1193 *
1194 * Or a query with aliasing:
1195 *
1196 * SELECT m.member_id, m.member_name FROM members AS m
1197 *
1198 * Since the column name can include up to four segments (host, DB, table, column)
1199 * or also have an alias prefix, we need to do a bit of work to figure this out and
1200 * insert the table prefix (if it exists) in the proper position, and escape only
1201 * the correct identifiers.
1202 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001203 * NOTE: This is used by DB_forge drivers and therefore needs to be public.
1204 * (until a better solution is implemented)
1205 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001206 * @param string
1207 * @param bool
1208 * @param mixed
1209 * @param bool
1210 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001211 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001212 public function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001213 {
1214 if ( ! is_bool($protect_identifiers))
1215 {
1216 $protect_identifiers = $this->_protect_identifiers;
1217 }
Derek Allarde37ab382009-02-03 16:13:57 +00001218
1219 if (is_array($item))
1220 {
1221 $escaped_array = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001222 foreach ($item as $k => $v)
Derek Allarde37ab382009-02-03 16:13:57 +00001223 {
1224 $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v);
1225 }
1226
1227 return $escaped_array;
1228 }
1229
Derek Allard2067d1a2008-11-13 22:59:24 +00001230 // Convert tabs or multiple spaces into single spaces
Derek Jones7b3b96c2009-02-10 21:01:47 +00001231 $item = preg_replace('/[\t ]+/', ' ', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001232
Derek Allard2067d1a2008-11-13 22:59:24 +00001233 // If the item has an alias declaration we remove it and set it aside.
1234 // Basically we remove everything to the right of the first space
Derek Allard2067d1a2008-11-13 22:59:24 +00001235 if (strpos($item, ' ') !== FALSE)
Derek Allard911d3e02008-12-15 14:08:35 +00001236 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001237 $alias = strstr($item, ' ');
Derek Allard2067d1a2008-11-13 22:59:24 +00001238 $item = substr($item, 0, - strlen($alias));
1239 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001240 else
1241 {
1242 $alias = '';
1243 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001244
Derek Allard911d3e02008-12-15 14:08:35 +00001245 // This is basically a bug fix for queries that use MAX, MIN, etc.
Barry Mienydd671972010-10-04 16:33:58 +02001246 // If a parenthesis is found we know that we do not need to
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001247 // escape the data or add a prefix. There's probably a more graceful
Derek Allard911d3e02008-12-15 14:08:35 +00001248 // way to deal with this, but I'm not thinking of it -- Rick
1249 if (strpos($item, '(') !== FALSE)
1250 {
1251 return $item.$alias;
1252 }
1253
Derek Allard2067d1a2008-11-13 22:59:24 +00001254 // Break the string apart if it contains periods, then insert the table prefix
1255 // in the correct location, assuming the period doesn't indicate that we're dealing
1256 // with an alias. While we're at it, we will escape the components
1257 if (strpos($item, '.') !== FALSE)
1258 {
1259 $parts = explode('.', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001260
Derek Allard2067d1a2008-11-13 22:59:24 +00001261 // Does the first segment of the exploded item match
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001262 // one of the aliases previously identified? If so,
Derek Allard2067d1a2008-11-13 22:59:24 +00001263 // we have nothing more to do other than escape the item
1264 if (in_array($parts[0], $this->ar_aliased_tables))
Derek Allard911d3e02008-12-15 14:08:35 +00001265 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001266 if ($protect_identifiers === TRUE)
1267 {
1268 foreach ($parts as $key => $val)
1269 {
1270 if ( ! in_array($val, $this->_reserved_identifiers))
1271 {
1272 $parts[$key] = $this->_escape_identifiers($val);
1273 }
1274 }
Barry Mienydd671972010-10-04 16:33:58 +02001275
Derek Allard2067d1a2008-11-13 22:59:24 +00001276 $item = implode('.', $parts);
Barry Mienydd671972010-10-04 16:33:58 +02001277 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001278
Derek Allard2067d1a2008-11-13 22:59:24 +00001279 return $item.$alias;
1280 }
Barry Mienydd671972010-10-04 16:33:58 +02001281
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001282 // Is there a table prefix defined in the config file? If not, no need to do anything
Derek Allard2067d1a2008-11-13 22:59:24 +00001283 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 Mienydd671972010-10-04 16:33:58 +02001304
Derek Allard2067d1a2008-11-13 22:59:24 +00001305 // 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 Mienydd671972010-10-04 16:33:58 +02001311
Derek Jones55acc8b2009-07-11 03:38:13 +00001312 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001313 if ($this->swap_pre != '' && strpos($parts[$i], $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001314 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001315 $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]);
Derek Jones55acc8b2009-07-11 03:38:13 +00001316 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001317 // We only add the table prefix if it does not already exist
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001318 elseif (strpos($parts[$i], $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001319 {
1320 $parts[$i] = $this->dbprefix.$parts[$i];
1321 }
Barry Mienydd671972010-10-04 16:33:58 +02001322
Derek Allard2067d1a2008-11-13 22:59:24 +00001323 // Put the parts back together
1324 $item = implode('.', $parts);
1325 }
Barry Mienydd671972010-10-04 16:33:58 +02001326
Derek Allard2067d1a2008-11-13 22:59:24 +00001327 if ($protect_identifiers === TRUE)
1328 {
1329 $item = $this->_escape_identifiers($item);
1330 }
Barry Mienydd671972010-10-04 16:33:58 +02001331
Derek Allard2067d1a2008-11-13 22:59:24 +00001332 return $item.$alias;
1333 }
1334
Derek Jones37f4b9c2011-07-01 17:56:50 -05001335 // Is there a table prefix? If not, no need to insert it
Derek Allard2067d1a2008-11-13 22:59:24 +00001336 if ($this->dbprefix != '')
1337 {
Derek Jones55acc8b2009-07-11 03:38:13 +00001338 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001339 if ($this->swap_pre != '' && strpos($item, $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001340 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001341 $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item);
Derek Jones55acc8b2009-07-11 03:38:13 +00001342 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001343 // Do we prefix an item with no segments?
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001344 elseif ($prefix_single == TRUE && strpos($item, $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001345 {
1346 $item = $this->dbprefix.$item;
Barry Mienydd671972010-10-04 16:33:58 +02001347 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001348 }
1349
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001350 if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers))
Derek Allard2067d1a2008-11-13 22:59:24 +00001351 {
1352 $item = $this->_escape_identifiers($item);
1353 }
Barry Mienydd671972010-10-04 16:33:58 +02001354
Derek Allard2067d1a2008-11-13 22:59:24 +00001355 return $item.$alias;
1356 }
Túbal Martín511f2252011-11-24 14:43:45 +01001357
1358 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +00001359
Túbal Martín511f2252011-11-24 14:43:45 +01001360 /**
1361 * Dummy method that allows Active Record class to be disabled
1362 *
1363 * This function is used extensively by every db driver.
1364 *
1365 * @access private
1366 * @return void
1367 */
1368 protected function _reset_select()
1369 {
1370
1371 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001372
1373}
1374
Derek Allard2067d1a2008-11-13 22:59:24 +00001375/* End of file DB_driver.php */
Andrey Andreevdc46d992011-09-24 16:25:23 +03001376/* Location: ./system/database/DB_driver.php */