blob: d3359e13eb32534b79ffd6e52cef9263c70bebdd [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 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 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 */
Timothy Warren7eeda532012-03-19 16:01:55 -040041abstract class CI_DB_driver {
Derek Allard2067d1a2008-11-13 22:59:24 +000042
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();
Derek Allard2067d1a2008-11-13 22:59:24 +000066
Andrey Andreevaf5d5582012-01-25 21:34:47 +020067 public $trans_enabled = TRUE;
68 public $trans_strict = TRUE;
69 protected $_trans_depth = 0;
70 protected $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
Derek Allard2067d1a2008-11-13 22:59:24 +000071
Andrey Andreevaf5d5582012-01-25 21:34:47 +020072 public $cache_on = FALSE;
73 public $cachedir = '';
74 public $cache_autodel = FALSE;
75 public $CACHE; // The cache class object
Derek Allard2067d1a2008-11-13 22:59:24 +000076
Andrey Andreev043f2602012-03-06 20:16:42 +020077 protected $_protect_identifiers = TRUE;
Andrey Andreevaf5d5582012-01-25 21:34:47 +020078 protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
Derek Allard2067d1a2008-11-13 22:59:24 +000079
Andrey Andreevaf5d5582012-01-25 21:34:47 +020080 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +000081 {
82 if (is_array($params))
83 {
84 foreach ($params as $key => $val)
85 {
86 $this->$key = $val;
87 }
88 }
89
90 log_message('debug', 'Database Driver Class Initialized');
91 }
Barry Mienydd671972010-10-04 16:33:58 +020092
Derek Allard2067d1a2008-11-13 22:59:24 +000093 // --------------------------------------------------------------------
94
95 /**
96 * Initialize Database Settings
97 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +020098 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020099 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200100 public function initialize()
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200102 /* If an established connection is available, then there's
103 * no need to connect and select the database.
104 *
105 * Depending on the database driver, conn_id can be either
106 * boolean TRUE, a resource or an object.
107 */
108 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 {
110 return TRUE;
111 }
Barry Mienydd671972010-10-04 16:33:58 +0200112
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200114
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 // Connect to the database and set the connection ID
116 $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
117
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200118 // No connection resource? Check if there is a failover else throw an error
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 if ( ! $this->conn_id)
120 {
Felix Balfoort5d581b62011-11-29 15:53:01 +0100121 // Check if there is a failover set
122 if ( ! empty($this->failover) && is_array($this->failover))
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 {
Felix Balfoort5d581b62011-11-29 15:53:01 +0100124 // Go over all the failovers
125 foreach ($this->failover as $failover)
126 {
127 // Replace the current settings with those of the failover
128 foreach ($failover as $key => $val)
129 {
130 $this->$key = $val;
131 }
132
133 // Try to connect
134 $this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
135
136 // If a connection is made break the foreach loop
137 if ($this->conn_id)
138 {
139 break;
140 }
141 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000142 }
Felix Balfoort5d581b62011-11-29 15:53:01 +0100143
144 // We still don't have a connection?
145 if ( ! $this->conn_id)
146 {
147 log_message('error', 'Unable to connect to the database');
148
149 if ($this->db_debug)
150 {
151 $this->display_error('db_unable_to_connect');
152 }
153 return FALSE;
154 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 }
156
157 // ----------------------------------------------------------------
158
159 // Select the DB... assuming a database name is specified in the config file
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200160 if ($this->database !== '' && ! $this->db_select())
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 {
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200162 log_message('error', 'Unable to select database: '.$this->database);
Barry Mienydd671972010-10-04 16:33:58 +0200163
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200164 if ($this->db_debug)
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 {
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200166 $this->display_error('db_unable_to_select', $this->database);
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 }
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200168 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 }
170
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200171 // Now we set the character set and that's all
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200172 return $this->db_set_charset($this->char_set);
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 }
Barry Mienydd671972010-10-04 16:33:58 +0200174
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 // --------------------------------------------------------------------
176
177 /**
Andrey Andreev2cae1932012-03-23 16:08:41 +0200178 * Reconnect
179 *
180 * Keep / reestablish the db connection if no queries have been
181 * sent for a length of time exceeding the server's idle timeout.
182 *
183 * This is just a dummy method to allow drivers without such
184 * functionality to not declare it, while others will override it.
185 *
186 * @return void
187 */
188 public function reconnect()
189 {
190 }
191
192 // --------------------------------------------------------------------
193
194 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 * Set client character set
196 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 * @param string
198 * @param string
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200199 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 */
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200201 public function db_set_charset($charset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 {
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200203 if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset))
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200205 log_message('error', 'Unable to set database connection charset: '.$charset);
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 if ($this->db_debug)
208 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200209 $this->display_error('db_unable_to_set_charset', $charset);
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 }
Barry Mienydd671972010-10-04 16:33:58 +0200211
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 return FALSE;
213 }
Barry Mienydd671972010-10-04 16:33:58 +0200214
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 return TRUE;
216 }
Barry Mienydd671972010-10-04 16:33:58 +0200217
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 // --------------------------------------------------------------------
219
220 /**
221 * The name of the platform in use (mysql, mssql, etc...)
222 *
Barry Mienydd671972010-10-04 16:33:58 +0200223 * @return string
224 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200225 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 {
227 return $this->dbdriver;
228 }
229
230 // --------------------------------------------------------------------
231
232 /**
Andrey Andreev08856b82012-03-03 03:19:28 +0200233 * Database version number
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 *
Andrey Andreev08856b82012-03-03 03:19:28 +0200235 * Returns a string containing the version of the database being used.
236 * Most drivers will override this method.
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 *
Barry Mienydd671972010-10-04 16:33:58 +0200238 * @return string
239 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200240 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200242 if (isset($this->data_cache['version']))
243 {
244 return $this->data_cache['version'];
245 }
246
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 if (FALSE === ($sql = $this->_version()))
248 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200249 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 }
Derek Allard3683f772009-12-16 17:32:33 +0000251
Andrey Andreev08856b82012-03-03 03:19:28 +0200252 $query = $this->query($sql);
253 $query = $query->row();
254 return $this->data_cache['version'] = $query->ver;
255 }
Derek Allard3683f772009-12-16 17:32:33 +0000256
Andrey Andreev08856b82012-03-03 03:19:28 +0200257 // --------------------------------------------------------------------
258
259 /**
260 * Version number query string
261 *
262 * @return string
263 */
264 protected function _version()
265 {
266 return 'SELECT VERSION() AS ver';
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 }
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 // --------------------------------------------------------------------
270
271 /**
272 * Execute the query
273 *
274 * Accepts an SQL string as input and returns a result object upon
Andrey Andreev4c202602012-03-06 20:34:52 +0200275 * successful execution of a "read" type query. Returns boolean TRUE
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 * upon successful execution of a "write" type query. Returns boolean
277 * FALSE upon failure, and if the $db_debug variable is set to TRUE
278 * will raise an error.
279 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 * @param string An SQL query string
281 * @param array An array of binding data
Barry Mienydd671972010-10-04 16:33:58 +0200282 * @return mixed
283 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200284 public function query($sql, $binds = FALSE, $return_object = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 {
286 if ($sql == '')
287 {
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200288 log_message('error', 'Invalid query: '.$sql);
289
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200290 return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 }
292
293 // Verify table prefix and replace if necessary
Andrey Andreev6202a3c2012-03-28 14:46:24 +0300294 if ($this->dbprefix != '' && $this->swap_pre != '' && $this->dbprefix != $this->swap_pre)
Derek Jonese7792202010-03-02 17:24:46 -0600295 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200296 $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 }
Derek Jonese7792202010-03-02 17:24:46 -0600298
Ryan Dialef7474c2012-03-01 16:11:36 -0500299 // Compile binds if needed
300 if ($binds !== FALSE)
301 {
302 $sql = $this->compile_binds($sql, $binds);
303 }
304
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200305 // Is query caching enabled? If the query is a "read type"
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 // we will load the caching class and return the previously
307 // cached query if it exists
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200308 if ($this->cache_on == TRUE && stripos($sql, 'SELECT') !== FALSE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200310 $this->load_rdriver();
311 if (FALSE !== ($cache = $this->CACHE->read($sql)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200313 return $cache;
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 }
315 }
Barry Mienydd671972010-10-04 16:33:58 +0200316
Derek Jones37f4b9c2011-07-01 17:56:50 -0500317 // Save the query for debugging
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 if ($this->save_queries == TRUE)
319 {
320 $this->queries[] = $sql;
321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 // Start the Query Timer
324 $time_start = list($sm, $ss) = explode(' ', microtime());
Barry Mienydd671972010-10-04 16:33:58 +0200325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 // Run the Query
327 if (FALSE === ($this->result_id = $this->simple_query($sql)))
328 {
329 if ($this->save_queries == TRUE)
330 {
331 $this->query_times[] = 0;
332 }
Barry Mienydd671972010-10-04 16:33:58 +0200333
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 // This will trigger a rollback if transactions are being used
335 $this->_trans_status = FALSE;
336
Andrey Andreev4be5de12012-03-02 15:45:41 +0200337 // Grab the error now, as we might run some additional queries before displaying the error
338 $error = $this->error();
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200339
340 // Log errors
Andrey Andreev4be5de12012-03-02 15:45:41 +0200341 log_message('error', 'Query error: '.$error['message']);
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200342
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 if ($this->db_debug)
344 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 // We call this function in order to roll-back queries
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200346 // if transactions are enabled. If we don't call this here
Barry Mienydd671972010-10-04 16:33:58 +0200347 // the error message will trigger an exit, causing the
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 // transactions to remain in limbo.
349 $this->trans_complete();
350
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200351 // Display errors
Andrey Andreev27984582012-03-03 04:43:10 +0200352 return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql));
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 }
Barry Mienydd671972010-10-04 16:33:58 +0200354
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 return FALSE;
356 }
Barry Mienydd671972010-10-04 16:33:58 +0200357
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 // 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 Mienydd671972010-10-04 16:33:58 +0200366
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 // Increment the query counter
368 $this->query_count++;
Barry Mienydd671972010-10-04 16:33:58 +0200369
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 // 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
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200376 if ($this->cache_on == TRUE && $this->cache_autodel == TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 {
378 $this->CACHE->delete();
379 }
Barry Mienydd671972010-10-04 16:33:58 +0200380
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 return TRUE;
382 }
Barry Mienydd671972010-10-04 16:33:58 +0200383
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 // 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 Mienydd671972010-10-04 16:33:58 +0200391
392 // Load and instantiate the result driver
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200393 $driver = $this->load_rdriver();
Andrey Andreev57bdeb62012-03-05 15:59:16 +0200394 $RES = new $driver($this);
Derek Allard2067d1a2008-11-13 22:59:24 +0000395
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 $RES->num_rows = $RES->num_rows();
Barry Mienydd671972010-10-04 16:33:58 +0200397
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200398 // Is query caching enabled? If so, we'll serialize the
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 // result object and save it to a cache file.
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200400 if ($this->cache_on == TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 {
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();
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 $CR->result_object = $RES->result_object();
410 $CR->result_array = $RES->result_array();
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200411 $CR->num_rows = $RES->num_rows();
Barry Mienydd671972010-10-04 16:33:58 +0200412
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 // 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 Mienydd671972010-10-04 16:33:58 +0200419
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 return $RES;
421 }
422
423 // --------------------------------------------------------------------
424
425 /**
426 * Load the result drivers
427 *
Barry Mienydd671972010-10-04 16:33:58 +0200428 * @return string the name of the result class
429 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200430 public function load_rdriver()
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 {
432 $driver = 'CI_DB_'.$this->dbdriver.'_result';
433
434 if ( ! class_exists($driver))
435 {
Greg Aker3a746652011-04-19 10:59:47 -0500436 include_once(BASEPATH.'database/DB_result.php');
437 include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 }
Barry Mienydd671972010-10-04 16:33:58 +0200439
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 return $driver;
441 }
Barry Mienydd671972010-10-04 16:33:58 +0200442
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 // --------------------------------------------------------------------
444
445 /**
446 * Simple Query
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200447 * This is a simplified version of the query() function. Internally
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 * we only use it when running transaction commands since they do
449 * not require all the features of the main query() function.
450 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * @param string the sql query
Barry Mienydd671972010-10-04 16:33:58 +0200452 * @return mixed
453 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200454 public function simple_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 {
456 if ( ! $this->conn_id)
457 {
458 $this->initialize();
459 }
460
461 return $this->_execute($sql);
462 }
Barry Mienydd671972010-10-04 16:33:58 +0200463
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 // --------------------------------------------------------------------
465
466 /**
467 * Disable Transactions
468 * This permits transactions to be disabled at run-time.
469 *
Barry Mienydd671972010-10-04 16:33:58 +0200470 * @return void
471 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200472 public function trans_off()
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 {
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 Mienydd671972010-10-04 16:33:58 +0200486 * @return void
487 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200488 public function trans_strict($mode = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 {
490 $this->trans_strict = is_bool($mode) ? $mode : TRUE;
491 }
Barry Mienydd671972010-10-04 16:33:58 +0200492
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 // --------------------------------------------------------------------
494
495 /**
496 * Start Transaction
497 *
Barry Mienydd671972010-10-04 16:33:58 +0200498 * @return void
499 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200500 public function trans_start($test_mode = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200501 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 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 Mienydd671972010-10-04 16:33:58 +0200513
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 $this->trans_begin($test_mode);
Jacob Terry07fcedf2011-11-22 11:21:36 -0500515 $this->_trans_depth += 1;
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 }
517
518 // --------------------------------------------------------------------
519
520 /**
521 * Complete Transaction
522 *
Barry Mienydd671972010-10-04 16:33:58 +0200523 * @return bool
524 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200525 public function trans_complete()
Derek Allard2067d1a2008-11-13 22:59:24 +0000526 {
527 if ( ! $this->trans_enabled)
528 {
529 return FALSE;
530 }
Barry Mienydd671972010-10-04 16:33:58 +0200531
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 // 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 Terry07fcedf2011-11-22 11:21:36 -0500538 else
539 {
540 $this->_trans_depth = 0;
541 }
Barry Mienydd671972010-10-04 16:33:58 +0200542
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 // 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 Mienydd671972010-10-04 16:33:58 +0200547
Derek Allard2067d1a2008-11-13 22:59:24 +0000548 // 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 Mienydd671972010-10-04 16:33:58 +0200559
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 $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 Mienydd671972010-10-04 16:33:58 +0200569 * @return bool
570 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200571 public function trans_status()
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 {
573 return $this->_trans_status;
574 }
575
576 // --------------------------------------------------------------------
577
578 /**
579 * Compile Bindings
580 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 * @param string the sql statement
582 * @param array an array of bind data
Barry Mienydd671972010-10-04 16:33:58 +0200583 * @return string
584 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200585 public function compile_binds($sql, $binds)
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 {
587 if (strpos($sql, $this->bind_marker) === FALSE)
588 {
589 return $sql;
590 }
Barry Mienydd671972010-10-04 16:33:58 +0200591
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 if ( ! is_array($binds))
593 {
594 $binds = array($binds);
595 }
Barry Mienydd671972010-10-04 16:33:58 +0200596
Derek Allard2067d1a2008-11-13 22:59:24 +0000597 // 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
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200602 if (count($binds) >= count($segments))
603 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 $binds = array_slice($binds, 0, count($segments)-1);
605 }
606
607 // Construct the binded query
608 $result = $segments[0];
609 $i = 0;
610 foreach ($binds as $bind)
611 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200612 $result .= $this->escape($bind).$segments[++$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 }
614
615 return $result;
616 }
Barry Mienydd671972010-10-04 16:33:58 +0200617
Derek Allard2067d1a2008-11-13 22:59:24 +0000618 // --------------------------------------------------------------------
619
620 /**
621 * Determines if a query is a "write" type.
622 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000623 * @param string An SQL query string
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200624 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200625 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200626 public function is_write_type($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000627 {
Andrey Andreev5fa72982012-03-03 04:13:20 +0200628 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 +0000629 }
Barry Mienydd671972010-10-04 16:33:58 +0200630
Derek Allard2067d1a2008-11-13 22:59:24 +0000631 // --------------------------------------------------------------------
632
633 /**
634 * Calculate the aggregate query elapsed time
635 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200636 * @param int The number of decimal places
637 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200638 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200639 public function elapsed_time($decimals = 6)
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 {
641 return number_format($this->benchmark, $decimals);
642 }
Barry Mienydd671972010-10-04 16:33:58 +0200643
Derek Allard2067d1a2008-11-13 22:59:24 +0000644 // --------------------------------------------------------------------
645
646 /**
647 * Returns the total number of queries
648 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200649 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200650 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200651 public function total_queries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000652 {
653 return $this->query_count;
654 }
Barry Mienydd671972010-10-04 16:33:58 +0200655
Derek Allard2067d1a2008-11-13 22:59:24 +0000656 // --------------------------------------------------------------------
657
658 /**
659 * Returns the last query that was executed
660 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200661 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200662 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200663 public function last_query()
Derek Allard2067d1a2008-11-13 22:59:24 +0000664 {
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 Allard2067d1a2008-11-13 22:59:24 +0000676 * @param string
Barry Mienydd671972010-10-04 16:33:58 +0200677 * @return mixed
678 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200679 public function escape($str)
Barry Mienydd671972010-10-04 16:33:58 +0200680 {
Joel Kallman10aa8e62012-03-09 14:54:53 -0500681 if (is_string($str) OR method_exists($str, '__toString'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000682 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200683 return "'".$this->escape_str($str)."'";
Derek Jonesa377bdd2009-02-11 18:55:24 +0000684 }
685 elseif (is_bool($str))
686 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200687 return ($str === FALSE) ? 0 : 1;
Derek Jonesa377bdd2009-02-11 18:55:24 +0000688 }
689 elseif (is_null($str))
690 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200691 return 'NULL';
Derek Jonesa377bdd2009-02-11 18:55:24 +0000692 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000693
694 return $str;
695 }
696
697 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600698
Derek Jonese4ed5832009-02-20 21:44:59 +0000699 /**
Derek Jonesbdc7fb92009-02-20 21:55:10 +0000700 * Escape LIKE String
Derek Jonese4ed5832009-02-20 21:44:59 +0000701 *
702 * Calls the individual driver for platform
703 * specific escaping for LIKE conditions
Barry Mienydd671972010-10-04 16:33:58 +0200704 *
Derek Jonese4ed5832009-02-20 21:44:59 +0000705 * @param string
706 * @return mixed
707 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200708 public function escape_like_str($str)
Barry Mienydd671972010-10-04 16:33:58 +0200709 {
710 return $this->escape_str($str, TRUE);
Derek Jonese4ed5832009-02-20 21:44:59 +0000711 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000712
Derek Jonese4ed5832009-02-20 21:44:59 +0000713 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600714
Derek Allard2067d1a2008-11-13 22:59:24 +0000715 /**
716 * Primary
717 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200718 * Retrieves the primary key. It assumes that the row in the first
Derek Allard2067d1a2008-11-13 22:59:24 +0000719 * position is the primary key
720 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000721 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200722 * @return string
723 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200724 public function primary($table = '')
Barry Mienydd671972010-10-04 16:33:58 +0200725 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000726 $fields = $this->list_fields($table);
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200727 return is_array($fields) ? current($fields) : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000728 }
729
730 // --------------------------------------------------------------------
731
732 /**
733 * Returns an array of table names
734 *
Barry Mienydd671972010-10-04 16:33:58 +0200735 * @return array
736 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200737 public function list_tables($constrain_by_prefix = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000738 {
739 // Is there a cached result?
740 if (isset($this->data_cache['table_names']))
741 {
742 return $this->data_cache['table_names'];
743 }
Barry Mienydd671972010-10-04 16:33:58 +0200744
Derek Allard2067d1a2008-11-13 22:59:24 +0000745 if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix)))
746 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200747 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000748 }
749
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200750 $this->data_cache['table_names'] = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000751 $query = $this->query($sql);
Barry Mienydd671972010-10-04 16:33:58 +0200752
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200753 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000754 {
Andrey Andreev12567e82012-01-25 22:50:33 +0200755 // Do we know from which column to get the table name?
756 if ( ! isset($key))
757 {
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300758 if (isset($row['table_name']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200759 {
760 $key = 'table_name';
761 }
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300762 elseif (isset($row['TABLE_NAME']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200763 {
764 $key = 'TABLE_NAME';
765 }
766 else
767 {
768 /* We have no other choice but to just get the first element's key.
769 * Due to array_shift() accepting it's argument by reference, if
770 * E_STRICT is on, this would trigger a warning. So we'll have to
771 * assign it first.
772 */
773 $key = array_keys($row);
774 $key = array_shift($key);
775 }
776 }
777
778 $this->data_cache['table_names'][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000779 }
780
Derek Allard2067d1a2008-11-13 22:59:24 +0000781 return $this->data_cache['table_names'];
782 }
Barry Mienydd671972010-10-04 16:33:58 +0200783
Derek Allard2067d1a2008-11-13 22:59:24 +0000784 // --------------------------------------------------------------------
785
786 /**
787 * Determine if a particular table exists
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200788 *
789 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000790 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200791 public function table_exists($table_name)
Barry Mienydd671972010-10-04 16:33:58 +0200792 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200793 return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables());
Derek Allard2067d1a2008-11-13 22:59:24 +0000794 }
Barry Mienydd671972010-10-04 16:33:58 +0200795
Derek Allard2067d1a2008-11-13 22:59:24 +0000796 // --------------------------------------------------------------------
797
798 /**
799 * Fetch MySQL Field Names
800 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000801 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200802 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000803 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200804 public function list_fields($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000805 {
806 // Is there a cached result?
807 if (isset($this->data_cache['field_names'][$table]))
808 {
809 return $this->data_cache['field_names'][$table];
810 }
Barry Mienydd671972010-10-04 16:33:58 +0200811
Derek Allard2067d1a2008-11-13 22:59:24 +0000812 if ($table == '')
813 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200814 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 }
Barry Mienydd671972010-10-04 16:33:58 +0200816
Greg Aker1edde302010-01-26 00:17:01 +0000817 if (FALSE === ($sql = $this->_list_columns($table)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000818 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200819 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000820 }
Barry Mienydd671972010-10-04 16:33:58 +0200821
Derek Allard2067d1a2008-11-13 22:59:24 +0000822 $query = $this->query($sql);
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200823 $this->data_cache['field_names'][$table] = array();
Barry Mienydd671972010-10-04 16:33:58 +0200824
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500825 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000826 {
Andrey Andreev12567e82012-01-25 22:50:33 +0200827 // Do we know from where to get the column's name?
828 if ( ! isset($key))
829 {
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300830 if (isset($row['column_name']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200831 {
832 $key = 'column_name';
833 }
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300834 elseif (isset($row['COLUMN_NAME']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200835 {
836 $key = 'COLUMN_NAME';
837 }
838 else
839 {
840 /* We have no other choice but to just get the first element's key.
841 * Due to array_shift() accepting it's argument by reference, if
842 * E_STRICT is on, this would trigger a warning. So we'll have to
843 * assign it first.
844 */
845 $key = array_keys($row);
846 $key = array_shift($key);
847 }
848 }
849
850 $this->data_cache['field_names'][$table][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000851 }
Barry Mienydd671972010-10-04 16:33:58 +0200852
Derek Allard2067d1a2008-11-13 22:59:24 +0000853 return $this->data_cache['field_names'][$table];
854 }
855
856 // --------------------------------------------------------------------
857
858 /**
859 * Determine if a particular field exists
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200860 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000861 * @param string
862 * @param string
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200863 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000864 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200865 public function field_exists($field_name, $table_name)
Barry Mienydd671972010-10-04 16:33:58 +0200866 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200867 return in_array($field_name, $this->list_fields($table_name));
Derek Allard2067d1a2008-11-13 22:59:24 +0000868 }
Barry Mienydd671972010-10-04 16:33:58 +0200869
Derek Allard2067d1a2008-11-13 22:59:24 +0000870 // --------------------------------------------------------------------
871
872 /**
873 * Returns an object with field data
874 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000875 * @param string the table name
Andrey Andreev5d93e132012-03-06 20:36:21 +0200876 * @return object
Barry Mienydd671972010-10-04 16:33:58 +0200877 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200878 public function field_data($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000879 {
880 if ($table == '')
881 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200882 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000883 }
Barry Mienydd671972010-10-04 16:33:58 +0200884
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200885 $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE)));
Derek Allard2067d1a2008-11-13 22:59:24 +0000886 return $query->field_data();
Barry Mienydd671972010-10-04 16:33:58 +0200887 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000888
889 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200890
Derek Allard2067d1a2008-11-13 22:59:24 +0000891 /**
892 * Generate an insert string
893 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000894 * @param string the table upon which the query will be performed
895 * @param array an associative array data of key/values
Barry Mienydd671972010-10-04 16:33:58 +0200896 * @return string
897 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200898 public function insert_string($table, $data)
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200900 $fields = $values = array();
Barry Mienydd671972010-10-04 16:33:58 +0200901
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500902 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000903 {
904 $fields[] = $this->_escape_identifiers($key);
905 $values[] = $this->escape($val);
906 }
Barry Mienydd671972010-10-04 16:33:58 +0200907
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200908 return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
Barry Mienydd671972010-10-04 16:33:58 +0200909 }
910
Derek Allard2067d1a2008-11-13 22:59:24 +0000911 // --------------------------------------------------------------------
912
913 /**
914 * Generate an update string
915 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 * @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 Mienydd671972010-10-04 16:33:58 +0200919 * @return string
920 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200921 public function update_string($table, $data, $where)
Derek Allard2067d1a2008-11-13 22:59:24 +0000922 {
923 if ($where == '')
924 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200925 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000926 }
Barry Mienydd671972010-10-04 16:33:58 +0200927
Derek Allard2067d1a2008-11-13 22:59:24 +0000928 $fields = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500929 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000930 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200931 $fields[$this->protect_identifiers($key)] = $this->escape($val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000932 }
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 Andreev032e7ea2012-03-06 19:48:35 +0200944 $key = $this->protect_identifiers($key);
Barry Mienydd671972010-10-04 16:33:58 +0200945
Derek Allard2067d1a2008-11-13 22:59:24 +0000946 if ($val !== '')
947 {
948 if ( ! $this->_has_operator($key))
949 {
950 $key .= ' =';
951 }
Barry Mienydd671972010-10-04 16:33:58 +0200952
Derek Allard2067d1a2008-11-13 22:59:24 +0000953 $val = ' '.$this->escape($val);
954 }
Barry Mienydd671972010-10-04 16:33:58 +0200955
Derek Allard2067d1a2008-11-13 22:59:24 +0000956 $dest[] = $prefix.$key.$val;
957 }
Barry Mienydd671972010-10-04 16:33:58 +0200958 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000959
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200960 return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
Barry Mienydd671972010-10-04 16:33:58 +0200961 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000962
963 // --------------------------------------------------------------------
964
965 /**
966 * Tests whether the string has an SQL operator
967 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000968 * @param string
969 * @return bool
970 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200971 protected function _has_operator($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000972 {
Andrey Andreev043f2602012-03-06 20:16:42 +0200973 return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL)/i', trim($str));
Derek Allard2067d1a2008-11-13 22:59:24 +0000974 }
975
976 // --------------------------------------------------------------------
977
978 /**
979 * Enables a native PHP function to be run, using a platform agnostic wrapper.
980 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000981 * @param string the function name
982 * @param mixed any parameters needed by the function
Barry Mienydd671972010-10-04 16:33:58 +0200983 * @return mixed
984 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200985 public function call_function($function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000986 {
987 $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
Barry Mienydd671972010-10-04 16:33:58 +0200988
Derek Allard2067d1a2008-11-13 22:59:24 +0000989 if (FALSE === strpos($driver, $function))
990 {
991 $function = $driver.$function;
992 }
Barry Mienydd671972010-10-04 16:33:58 +0200993
Derek Allard2067d1a2008-11-13 22:59:24 +0000994 if ( ! function_exists($function))
995 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200996 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000997 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000998
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200999 return (func_num_args() > 1)
1000 ? call_user_func_array($function, array_splice(func_get_args(), 1))
1001 : call_user_func($function);
Derek Allard2067d1a2008-11-13 22:59:24 +00001002 }
1003
1004 // --------------------------------------------------------------------
1005
1006 /**
1007 * Set Cache Directory Path
1008 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001009 * @param string the path to the cache directory
1010 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001011 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001012 public function cache_set_path($path = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001013 {
1014 $this->cachedir = $path;
1015 }
1016
1017 // --------------------------------------------------------------------
1018
1019 /**
1020 * Enable Query Caching
1021 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001022 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001023 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001024 public function cache_on()
Derek Allard2067d1a2008-11-13 22:59:24 +00001025 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001026 return $this->cache_on = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001027 }
1028
1029 // --------------------------------------------------------------------
1030
1031 /**
1032 * Disable Query Caching
1033 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001034 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001035 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001036 public function cache_off()
Derek Allard2067d1a2008-11-13 22:59:24 +00001037 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001038 return $this->cache_on = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001039 }
Barry Mienydd671972010-10-04 16:33:58 +02001040
Derek Allard2067d1a2008-11-13 22:59:24 +00001041
1042 // --------------------------------------------------------------------
1043
1044 /**
1045 * Delete the cache files associated with a particular URI
1046 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001047 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001048 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001049 public function cache_delete($segment_one = '', $segment_two = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001050 {
Andrey Andreev043f2602012-03-06 20:16:42 +02001051 return ($this->_cache_init())
1052 ? $this->CACHE->delete($segment_one, $segment_two)
1053 : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001054 }
1055
1056 // --------------------------------------------------------------------
1057
1058 /**
1059 * Delete All cache files
1060 *
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001061 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001062 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001063 public function cache_delete_all()
Derek Allard2067d1a2008-11-13 22:59:24 +00001064 {
Andrey Andreev043f2602012-03-06 20:16:42 +02001065 return ($this->_cache_init())
1066 ? $this->CACHE->delete_all()
1067 : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001068 }
1069
1070 // --------------------------------------------------------------------
1071
1072 /**
1073 * Initialize the Cache Class
1074 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001075 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001076 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001077 protected function _cache_init()
Derek Allard2067d1a2008-11-13 22:59:24 +00001078 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001079 if (class_exists('CI_DB_Cache'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001080 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001081 if (is_object($this->CACHE))
Derek Allarde37ab382009-02-03 16:13:57 +00001082 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001083 return TRUE;
Derek Allarde37ab382009-02-03 16:13:57 +00001084 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001085 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001086 elseif ( ! @include_once(BASEPATH.'database/DB_cache.php'))
1087 {
1088 return $this->cache_off();
1089 }
Derek Allarde37ab382009-02-03 16:13:57 +00001090
Derek Allard2067d1a2008-11-13 22:59:24 +00001091 $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
1092 return TRUE;
1093 }
1094
1095 // --------------------------------------------------------------------
1096
1097 /**
1098 * Close DB Connection
1099 *
Barry Mienydd671972010-10-04 16:33:58 +02001100 * @return void
1101 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001102 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +00001103 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001104 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +00001105 {
1106 $this->_close($this->conn_id);
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001107 $this->conn_id = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001108 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 }
Barry Mienydd671972010-10-04 16:33:58 +02001110
Derek Allard2067d1a2008-11-13 22:59:24 +00001111 // --------------------------------------------------------------------
1112
1113 /**
1114 * Display an error message
1115 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001116 * @param string the error message
1117 * @param string any "swap" values
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001118 * @param bool whether to localize the message
Barry Mienydd671972010-10-04 16:33:58 +02001119 * @return string sends the application/error_db.php template
1120 */
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001121 public function display_error($error = '', $swap = '', $native = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001122 {
Derek Jonese7792202010-03-02 17:24:46 -06001123 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 $LANG->load('db');
1125
1126 $heading = $LANG->line('db_error_heading');
1127
1128 if ($native == TRUE)
1129 {
Andrey Andreev85a99cc2011-09-24 17:17:37 +03001130 $message = (array) $error;
Derek Allard2067d1a2008-11-13 22:59:24 +00001131 }
1132 else
1133 {
1134 $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
1135 }
Barry Mienydd671972010-10-04 16:33:58 +02001136
Pascal Kriete60f8c392010-08-25 18:03:28 +02001137 // Find the most likely culprit of the error by going through
1138 // the backtrace until the source file is no longer in the
1139 // database folder.
Pascal Kriete60f8c392010-08-25 18:03:28 +02001140 $trace = debug_backtrace();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001141 foreach ($trace as $call)
Pascal Kriete60f8c392010-08-25 18:03:28 +02001142 {
1143 if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
1144 {
1145 // Found it - use a relative path for safety
1146 $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
1147 $message[] = 'Line Number: '.$call['line'];
Pascal Kriete60f8c392010-08-25 18:03:28 +02001148 break;
1149 }
1150 }
Barry Mienydd671972010-10-04 16:33:58 +02001151
Derek Jonese7792202010-03-02 17:24:46 -06001152 $error =& load_class('Exceptions', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001153 echo $error->show_error($heading, $message, 'error_db');
1154 exit;
1155 }
1156
1157 // --------------------------------------------------------------------
1158
1159 /**
1160 * Protect Identifiers
1161 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001162 * This function is used extensively by the Active Record class, and by
Barry Mienydd671972010-10-04 16:33:58 +02001163 * a couple functions in this class.
Derek Allard2067d1a2008-11-13 22:59:24 +00001164 * It takes a column or table name (optionally with an alias) and inserts
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001165 * the table prefix onto it. Some logic is necessary in order to deal with
1166 * column names that include the path. Consider a query like this:
Derek Allard2067d1a2008-11-13 22:59:24 +00001167 *
1168 * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
1169 *
1170 * Or a query with aliasing:
1171 *
1172 * SELECT m.member_id, m.member_name FROM members AS m
1173 *
1174 * Since the column name can include up to four segments (host, DB, table, column)
1175 * or also have an alias prefix, we need to do a bit of work to figure this out and
1176 * insert the table prefix (if it exists) in the proper position, and escape only
1177 * the correct identifiers.
1178 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001179 * @param string
1180 * @param bool
1181 * @param mixed
1182 * @param bool
1183 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001184 */
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001185 public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001186 {
1187 if ( ! is_bool($protect_identifiers))
1188 {
1189 $protect_identifiers = $this->_protect_identifiers;
1190 }
Derek Allarde37ab382009-02-03 16:13:57 +00001191
1192 if (is_array($item))
1193 {
1194 $escaped_array = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001195 foreach ($item as $k => $v)
Derek Allarde37ab382009-02-03 16:13:57 +00001196 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001197 $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v);
Derek Allarde37ab382009-02-03 16:13:57 +00001198 }
1199
1200 return $escaped_array;
1201 }
1202
Derek Allard2067d1a2008-11-13 22:59:24 +00001203 // Convert tabs or multiple spaces into single spaces
Derek Jones7b3b96c2009-02-10 21:01:47 +00001204 $item = preg_replace('/[\t ]+/', ' ', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001205
Derek Allard2067d1a2008-11-13 22:59:24 +00001206 // If the item has an alias declaration we remove it and set it aside.
1207 // Basically we remove everything to the right of the first space
Derek Allard2067d1a2008-11-13 22:59:24 +00001208 if (strpos($item, ' ') !== FALSE)
Derek Allard911d3e02008-12-15 14:08:35 +00001209 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001210 $alias = strstr($item, ' ');
Derek Allard2067d1a2008-11-13 22:59:24 +00001211 $item = substr($item, 0, - strlen($alias));
1212 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001213 else
1214 {
1215 $alias = '';
1216 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001217
Derek Allard911d3e02008-12-15 14:08:35 +00001218 // This is basically a bug fix for queries that use MAX, MIN, etc.
Barry Mienydd671972010-10-04 16:33:58 +02001219 // If a parenthesis is found we know that we do not need to
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001220 // escape the data or add a prefix. There's probably a more graceful
Derek Allard911d3e02008-12-15 14:08:35 +00001221 // way to deal with this, but I'm not thinking of it -- Rick
1222 if (strpos($item, '(') !== FALSE)
1223 {
1224 return $item.$alias;
1225 }
1226
Derek Allard2067d1a2008-11-13 22:59:24 +00001227 // Break the string apart if it contains periods, then insert the table prefix
1228 // in the correct location, assuming the period doesn't indicate that we're dealing
1229 // with an alias. While we're at it, we will escape the components
1230 if (strpos($item, '.') !== FALSE)
1231 {
1232 $parts = explode('.', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001233
Derek Allard2067d1a2008-11-13 22:59:24 +00001234 // Does the first segment of the exploded item match
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001235 // one of the aliases previously identified? If so,
Derek Allard2067d1a2008-11-13 22:59:24 +00001236 // we have nothing more to do other than escape the item
1237 if (in_array($parts[0], $this->ar_aliased_tables))
Derek Allard911d3e02008-12-15 14:08:35 +00001238 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001239 if ($protect_identifiers === TRUE)
1240 {
1241 foreach ($parts as $key => $val)
1242 {
1243 if ( ! in_array($val, $this->_reserved_identifiers))
1244 {
1245 $parts[$key] = $this->_escape_identifiers($val);
1246 }
1247 }
Barry Mienydd671972010-10-04 16:33:58 +02001248
Derek Allard2067d1a2008-11-13 22:59:24 +00001249 $item = implode('.', $parts);
Barry Mienydd671972010-10-04 16:33:58 +02001250 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001251
Derek Allard2067d1a2008-11-13 22:59:24 +00001252 return $item.$alias;
1253 }
Barry Mienydd671972010-10-04 16:33:58 +02001254
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001255 // Is there a table prefix defined in the config file? If not, no need to do anything
Derek Allard2067d1a2008-11-13 22:59:24 +00001256 if ($this->dbprefix != '')
1257 {
1258 // We now add the table prefix based on some logic.
1259 // Do we have 4 segments (hostname.database.table.column)?
1260 // If so, we add the table prefix to the column name in the 3rd segment.
1261 if (isset($parts[3]))
1262 {
1263 $i = 2;
1264 }
1265 // Do we have 3 segments (database.table.column)?
1266 // If so, we add the table prefix to the column name in 2nd position
1267 elseif (isset($parts[2]))
1268 {
1269 $i = 1;
1270 }
1271 // Do we have 2 segments (table.column)?
1272 // If so, we add the table prefix to the column name in 1st segment
1273 else
1274 {
1275 $i = 0;
1276 }
Barry Mienydd671972010-10-04 16:33:58 +02001277
Derek Allard2067d1a2008-11-13 22:59:24 +00001278 // This flag is set when the supplied $item does not contain a field name.
1279 // This can happen when this function is being called from a JOIN.
1280 if ($field_exists == FALSE)
1281 {
1282 $i++;
1283 }
Barry Mienydd671972010-10-04 16:33:58 +02001284
Derek Jones55acc8b2009-07-11 03:38:13 +00001285 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001286 if ($this->swap_pre != '' && strpos($parts[$i], $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001287 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001288 $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]);
Derek Jones55acc8b2009-07-11 03:38:13 +00001289 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001290 // We only add the table prefix if it does not already exist
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001291 elseif (strpos($parts[$i], $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001292 {
1293 $parts[$i] = $this->dbprefix.$parts[$i];
1294 }
Barry Mienydd671972010-10-04 16:33:58 +02001295
Derek Allard2067d1a2008-11-13 22:59:24 +00001296 // Put the parts back together
1297 $item = implode('.', $parts);
1298 }
Barry Mienydd671972010-10-04 16:33:58 +02001299
Derek Allard2067d1a2008-11-13 22:59:24 +00001300 if ($protect_identifiers === TRUE)
1301 {
1302 $item = $this->_escape_identifiers($item);
1303 }
Barry Mienydd671972010-10-04 16:33:58 +02001304
Derek Allard2067d1a2008-11-13 22:59:24 +00001305 return $item.$alias;
1306 }
1307
Andrey Andreev4c202602012-03-06 20:34:52 +02001308 // Is there a table prefix? If not, no need to insert it
Derek Allard2067d1a2008-11-13 22:59:24 +00001309 if ($this->dbprefix != '')
1310 {
Derek Jones55acc8b2009-07-11 03:38:13 +00001311 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001312 if ($this->swap_pre != '' && strpos($item, $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001313 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001314 $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item);
Derek Jones55acc8b2009-07-11 03:38:13 +00001315 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001316 // Do we prefix an item with no segments?
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001317 elseif ($prefix_single == TRUE && strpos($item, $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001318 {
1319 $item = $this->dbprefix.$item;
Barry Mienydd671972010-10-04 16:33:58 +02001320 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001321 }
1322
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001323 if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers))
Derek Allard2067d1a2008-11-13 22:59:24 +00001324 {
1325 $item = $this->_escape_identifiers($item);
1326 }
Barry Mienydd671972010-10-04 16:33:58 +02001327
Derek Allard2067d1a2008-11-13 22:59:24 +00001328 return $item.$alias;
1329 }
Andrey Andreev4c598362012-03-06 14:58:37 +02001330
Túbal Martín511f2252011-11-24 14:43:45 +01001331 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +00001332
Túbal Martín511f2252011-11-24 14:43:45 +01001333 /**
1334 * Dummy method that allows Active Record class to be disabled
1335 *
1336 * This function is used extensively by every db driver.
1337 *
Túbal Martín511f2252011-11-24 14:43:45 +01001338 * @return void
1339 */
Timothy Warren7eeda532012-03-19 16:01:55 -04001340 abstract protected function _reset_select();
Derek Allard2067d1a2008-11-13 22:59:24 +00001341
1342}
1343
Derek Allard2067d1a2008-11-13 22:59:24 +00001344/* End of file DB_driver.php */
Andrey Andreev35bbb1a2012-03-20 15:33:55 +02001345/* Location: ./system/database/DB_driver.php */