blob: 9347ce3e1756d1b866bf0bea5bd2a8ec6336cc38 [file] [log] [blame]
Andrey Andreev4c202602012-03-06 20:34:52 +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 Andreev4c202602012-03-06 20:34:52 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev4c202602012-03-06 20:34:52 +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 Andreev738f5342012-03-06 20:43:40 +020043 public $dsn;
Andrey Andreevd1add432012-03-06 20:26:01 +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 Andreevd1add432012-03-06 20:26:01 +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 Andreevd1add432012-03-06 20:26:01 +020072 public $cache_on = FALSE;
73 public $cachedir = '';
74 public $cache_autodel = FALSE;
75 public $CACHE; // The cache class object
76
77 protected $_protect_identifiers = TRUE;
78 protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
79
Timothy Warrene45518d2012-03-06 07:38:00 -050080 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 Andreev82e8ac12012-02-22 19:35:34 +020098 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020099 */
Andrey Andreev82e8ac12012-02-22 19:35:34 +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 Andreev82e8ac12012-02-22 19:35:34 +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 Andreev063f5962012-02-27 12:20:52 +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 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500225 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.
237 *
Barry Mienydd671972010-10-04 16:33:58 +0200238 * @return string
239 */
Andrey Andreev08856b82012-03-03 03:19:28 +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 Andreev08856b82012-03-03 03:19:28 +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 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500284 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 Andreev4c202602012-03-06 20:34:52 +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 Andreev4be5de12012-03-02 15:45:41 +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 Andreev57bdeb62012-03-05 15:59:16 +0200393 $driver = $this->load_rdriver();
394 $RES = new $driver($this);
Barry Mienydd671972010-10-04 16:33:58 +0200395
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200396 // Is query caching enabled? If so, we'll serialize the
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 // result object and save it to a cache file.
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200398 if ($this->cache_on == TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 {
400 // We'll create a new instance of the result object
401 // only without the platform specific driver since
402 // we can't use it with cached data (the query result
403 // resource ID won't be any good once we've cached the
404 // result object, so we'll have to compile the data
405 // and save it)
406 $CR = new CI_DB_result();
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 $CR->result_object = $RES->result_object();
408 $CR->result_array = $RES->result_array();
Andrey Andreev24abcb92012-01-05 20:40:15 +0200409 $CR->num_rows = $RES->num_rows();
Barry Mienydd671972010-10-04 16:33:58 +0200410
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 // Reset these since cached objects can not utilize resource IDs.
412 $CR->conn_id = NULL;
413 $CR->result_id = NULL;
414
415 $this->CACHE->write($sql, $CR);
416 }
Barry Mienydd671972010-10-04 16:33:58 +0200417
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 return $RES;
419 }
420
421 // --------------------------------------------------------------------
422
423 /**
424 * Load the result drivers
425 *
Barry Mienydd671972010-10-04 16:33:58 +0200426 * @return string the name of the result class
427 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500428 public function load_rdriver()
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 {
430 $driver = 'CI_DB_'.$this->dbdriver.'_result';
431
432 if ( ! class_exists($driver))
433 {
Greg Aker3a746652011-04-19 10:59:47 -0500434 include_once(BASEPATH.'database/DB_result.php');
435 include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 }
Barry Mienydd671972010-10-04 16:33:58 +0200437
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 return $driver;
439 }
Barry Mienydd671972010-10-04 16:33:58 +0200440
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 // --------------------------------------------------------------------
442
443 /**
444 * Simple Query
Andrey Andreev4c202602012-03-06 20:34:52 +0200445 * This is a simplified version of the query() function. Internally
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 * we only use it when running transaction commands since they do
447 * not require all the features of the main query() function.
448 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 * @param string the sql query
Barry Mienydd671972010-10-04 16:33:58 +0200450 * @return mixed
451 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500452 public function simple_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 {
454 if ( ! $this->conn_id)
455 {
456 $this->initialize();
457 }
458
459 return $this->_execute($sql);
460 }
Barry Mienydd671972010-10-04 16:33:58 +0200461
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 // --------------------------------------------------------------------
463
464 /**
465 * Disable Transactions
466 * This permits transactions to be disabled at run-time.
467 *
Barry Mienydd671972010-10-04 16:33:58 +0200468 * @return void
469 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500470 public function trans_off()
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 {
472 $this->trans_enabled = FALSE;
473 }
474
475 // --------------------------------------------------------------------
476
477 /**
478 * Enable/disable Transaction Strict Mode
479 * When strict mode is enabled, if you are running multiple groups of
480 * transactions, if one group fails all groups will be rolled back.
481 * If strict mode is disabled, each group is treated autonomously, meaning
482 * a failure of one group will not affect any others
483 *
Barry Mienydd671972010-10-04 16:33:58 +0200484 * @return void
485 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500486 public function trans_strict($mode = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 {
488 $this->trans_strict = is_bool($mode) ? $mode : TRUE;
489 }
Barry Mienydd671972010-10-04 16:33:58 +0200490
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 // --------------------------------------------------------------------
492
493 /**
494 * Start Transaction
495 *
Barry Mienydd671972010-10-04 16:33:58 +0200496 * @return void
497 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500498 public function trans_start($test_mode = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200499 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 if ( ! $this->trans_enabled)
501 {
502 return FALSE;
503 }
504
505 // When transactions are nested we only begin/commit/rollback the outermost ones
506 if ($this->_trans_depth > 0)
507 {
508 $this->_trans_depth += 1;
509 return;
510 }
Barry Mienydd671972010-10-04 16:33:58 +0200511
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 $this->trans_begin($test_mode);
Jacob Terry07fcedf2011-11-22 11:21:36 -0500513 $this->_trans_depth += 1;
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 }
515
516 // --------------------------------------------------------------------
517
518 /**
519 * Complete Transaction
520 *
Barry Mienydd671972010-10-04 16:33:58 +0200521 * @return bool
522 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500523 public function trans_complete()
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 {
525 if ( ! $this->trans_enabled)
526 {
527 return FALSE;
528 }
Barry Mienydd671972010-10-04 16:33:58 +0200529
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 // When transactions are nested we only begin/commit/rollback the outermost ones
531 if ($this->_trans_depth > 1)
532 {
533 $this->_trans_depth -= 1;
534 return TRUE;
535 }
Jacob Terry07fcedf2011-11-22 11:21:36 -0500536 else
537 {
538 $this->_trans_depth = 0;
539 }
Barry Mienydd671972010-10-04 16:33:58 +0200540
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 // The query() function will set this flag to FALSE in the event that a query failed
542 if ($this->_trans_status === FALSE)
543 {
544 $this->trans_rollback();
Barry Mienydd671972010-10-04 16:33:58 +0200545
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 // If we are NOT running in strict mode, we will reset
547 // the _trans_status flag so that subsequent groups of transactions
548 // will be permitted.
549 if ($this->trans_strict === FALSE)
550 {
551 $this->_trans_status = TRUE;
552 }
553
554 log_message('debug', 'DB Transaction Failure');
555 return FALSE;
556 }
Barry Mienydd671972010-10-04 16:33:58 +0200557
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 $this->trans_commit();
559 return TRUE;
560 }
561
562 // --------------------------------------------------------------------
563
564 /**
565 * Lets you retrieve the transaction flag to determine if it has failed
566 *
Barry Mienydd671972010-10-04 16:33:58 +0200567 * @return bool
568 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500569 public function trans_status()
Derek Allard2067d1a2008-11-13 22:59:24 +0000570 {
571 return $this->_trans_status;
572 }
573
574 // --------------------------------------------------------------------
575
576 /**
577 * Compile Bindings
578 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 * @param string the sql statement
580 * @param array an array of bind data
Barry Mienydd671972010-10-04 16:33:58 +0200581 * @return string
582 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500583 public function compile_binds($sql, $binds)
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 {
585 if (strpos($sql, $this->bind_marker) === FALSE)
586 {
587 return $sql;
588 }
Barry Mienydd671972010-10-04 16:33:58 +0200589
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 if ( ! is_array($binds))
591 {
592 $binds = array($binds);
593 }
Barry Mienydd671972010-10-04 16:33:58 +0200594
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 // Get the sql segments around the bind markers
596 $segments = explode($this->bind_marker, $sql);
597
598 // The count of bind should be 1 less then the count of segments
599 // If there are more bind arguments trim it down
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200600 if (count($binds) >= count($segments))
601 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 $binds = array_slice($binds, 0, count($segments)-1);
603 }
604
605 // Construct the binded query
606 $result = $segments[0];
607 $i = 0;
608 foreach ($binds as $bind)
609 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200610 $result .= $this->escape($bind).$segments[++$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000611 }
612
613 return $result;
614 }
Barry Mienydd671972010-10-04 16:33:58 +0200615
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 // --------------------------------------------------------------------
617
618 /**
619 * Determines if a query is a "write" type.
620 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 * @param string An SQL query string
Andrey Andreev67f71a42012-03-01 16:18:42 +0200622 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200623 */
Andrey Andreev67f71a42012-03-01 16:18:42 +0200624 public function is_write_type($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000625 {
Andrey Andreev5fa72982012-03-03 04:13:20 +0200626 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 +0000627 }
Barry Mienydd671972010-10-04 16:33:58 +0200628
Derek Allard2067d1a2008-11-13 22:59:24 +0000629 // --------------------------------------------------------------------
630
631 /**
632 * Calculate the aggregate query elapsed time
633 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200634 * @param int The number of decimal places
635 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200636 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500637 public function elapsed_time($decimals = 6)
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 {
639 return number_format($this->benchmark, $decimals);
640 }
Barry Mienydd671972010-10-04 16:33:58 +0200641
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 // --------------------------------------------------------------------
643
644 /**
645 * Returns the total number of queries
646 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200647 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200648 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500649 public function total_queries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000650 {
651 return $this->query_count;
652 }
Barry Mienydd671972010-10-04 16:33:58 +0200653
Derek Allard2067d1a2008-11-13 22:59:24 +0000654 // --------------------------------------------------------------------
655
656 /**
657 * Returns the last query that was executed
658 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200659 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200660 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500661 public function last_query()
Derek Allard2067d1a2008-11-13 22:59:24 +0000662 {
663 return end($this->queries);
664 }
665
666 // --------------------------------------------------------------------
667
668 /**
669 * "Smart" Escape String
670 *
671 * Escapes data based on type
672 * Sets boolean and null types
673 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000674 * @param string
Barry Mienydd671972010-10-04 16:33:58 +0200675 * @return mixed
676 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500677 public function escape($str)
Barry Mienydd671972010-10-04 16:33:58 +0200678 {
Joel Kallman10aa8e62012-03-09 14:54:53 -0500679 if (is_string($str) OR method_exists($str, '__toString'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000680 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200681 return "'".$this->escape_str($str)."'";
Derek Jonesa377bdd2009-02-11 18:55:24 +0000682 }
683 elseif (is_bool($str))
684 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200685 return ($str === FALSE) ? 0 : 1;
Derek Jonesa377bdd2009-02-11 18:55:24 +0000686 }
687 elseif (is_null($str))
688 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200689 return 'NULL';
Derek Jonesa377bdd2009-02-11 18:55:24 +0000690 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000691
692 return $str;
693 }
694
695 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600696
Derek Jonese4ed5832009-02-20 21:44:59 +0000697 /**
Derek Jonesbdc7fb92009-02-20 21:55:10 +0000698 * Escape LIKE String
Derek Jonese4ed5832009-02-20 21:44:59 +0000699 *
700 * Calls the individual driver for platform
701 * specific escaping for LIKE conditions
Barry Mienydd671972010-10-04 16:33:58 +0200702 *
Derek Jonese4ed5832009-02-20 21:44:59 +0000703 * @param string
704 * @return mixed
705 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500706 public function escape_like_str($str)
Barry Mienydd671972010-10-04 16:33:58 +0200707 {
708 return $this->escape_str($str, TRUE);
Derek Jonese4ed5832009-02-20 21:44:59 +0000709 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000710
Derek Jonese4ed5832009-02-20 21:44:59 +0000711 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600712
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 /**
714 * Primary
715 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200716 * Retrieves the primary key. It assumes that the row in the first
Derek Allard2067d1a2008-11-13 22:59:24 +0000717 * position is the primary key
718 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000719 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200720 * @return string
721 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500722 public function primary($table = '')
Barry Mienydd671972010-10-04 16:33:58 +0200723 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000724 $fields = $this->list_fields($table);
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200725 return is_array($fields) ? current($fields) : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000726 }
727
728 // --------------------------------------------------------------------
729
730 /**
731 * Returns an array of table names
732 *
Barry Mienydd671972010-10-04 16:33:58 +0200733 * @return array
734 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500735 public function list_tables($constrain_by_prefix = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000736 {
737 // Is there a cached result?
738 if (isset($this->data_cache['table_names']))
739 {
740 return $this->data_cache['table_names'];
741 }
Barry Mienydd671972010-10-04 16:33:58 +0200742
Derek Allard2067d1a2008-11-13 22:59:24 +0000743 if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix)))
744 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200745 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 }
747
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200748 $this->data_cache['table_names'] = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000749 $query = $this->query($sql);
Barry Mienydd671972010-10-04 16:33:58 +0200750
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200751 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000752 {
Andrey Andreev12567e82012-01-25 22:50:33 +0200753 // Do we know from which column to get the table name?
754 if ( ! isset($key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000755 {
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300756 if (isset($row['table_name']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200757 {
758 $key = 'table_name';
759 }
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300760 elseif (isset($row['TABLE_NAME']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200761 {
762 $key = 'TABLE_NAME';
763 }
764 else
765 {
766 /* We have no other choice but to just get the first element's key.
767 * Due to array_shift() accepting it's argument by reference, if
768 * E_STRICT is on, this would trigger a warning. So we'll have to
769 * assign it first.
770 */
771 $key = array_keys($row);
772 $key = array_shift($key);
773 }
Taufan Aditya18209332012-02-09 16:07:27 +0700774 }
775
Andrey Andreev12567e82012-01-25 22:50:33 +0200776 $this->data_cache['table_names'][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000777 }
778
Derek Allard2067d1a2008-11-13 22:59:24 +0000779 return $this->data_cache['table_names'];
780 }
Barry Mienydd671972010-10-04 16:33:58 +0200781
Derek Allard2067d1a2008-11-13 22:59:24 +0000782 // --------------------------------------------------------------------
783
784 /**
785 * Determine if a particular table exists
Timothy Warrene45518d2012-03-06 07:38:00 -0500786 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200787 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000788 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500789 public function table_exists($table_name)
Barry Mienydd671972010-10-04 16:33:58 +0200790 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200791 return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables());
Derek Allard2067d1a2008-11-13 22:59:24 +0000792 }
Barry Mienydd671972010-10-04 16:33:58 +0200793
Derek Allard2067d1a2008-11-13 22:59:24 +0000794 // --------------------------------------------------------------------
795
796 /**
Andrey Andreev569091c2012-02-09 00:16:17 +0200797 * Fetch MySQL Field Names
Derek Allard2067d1a2008-11-13 22:59:24 +0000798 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000799 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200800 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000801 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500802 public function list_fields($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000803 {
804 // Is there a cached result?
805 if (isset($this->data_cache['field_names'][$table]))
806 {
807 return $this->data_cache['field_names'][$table];
808 }
Barry Mienydd671972010-10-04 16:33:58 +0200809
Derek Allard2067d1a2008-11-13 22:59:24 +0000810 if ($table == '')
811 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200812 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000813 }
Barry Mienydd671972010-10-04 16:33:58 +0200814
Greg Aker1edde302010-01-26 00:17:01 +0000815 if (FALSE === ($sql = $this->_list_columns($table)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000816 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200817 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000818 }
Barry Mienydd671972010-10-04 16:33:58 +0200819
Derek Allard2067d1a2008-11-13 22:59:24 +0000820 $query = $this->query($sql);
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200821 $this->data_cache['field_names'][$table] = array();
Barry Mienydd671972010-10-04 16:33:58 +0200822
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500823 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +0000824 {
Andrey Andreev12567e82012-01-25 22:50:33 +0200825 // Do we know from where to get the column's name?
826 if ( ! isset($key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000827 {
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300828 if (isset($row['column_name']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200829 {
830 $key = 'column_name';
831 }
Andrey Andreev6781a5f2012-03-28 14:50:51 +0300832 elseif (isset($row['COLUMN_NAME']))
Andrey Andreev12567e82012-01-25 22:50:33 +0200833 {
834 $key = 'COLUMN_NAME';
835 }
836 else
837 {
838 /* We have no other choice but to just get the first element's key.
839 * Due to array_shift() accepting it's argument by reference, if
840 * E_STRICT is on, this would trigger a warning. So we'll have to
841 * assign it first.
842 */
843 $key = array_keys($row);
844 $key = array_shift($key);
845 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000846 }
Andrey Andreev12567e82012-01-25 22:50:33 +0200847
848 $this->data_cache['field_names'][$table][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000849 }
Barry Mienydd671972010-10-04 16:33:58 +0200850
Derek Allard2067d1a2008-11-13 22:59:24 +0000851 return $this->data_cache['field_names'][$table];
852 }
853
854 // --------------------------------------------------------------------
855
856 /**
857 * Determine if a particular field exists
Timothy Warrene45518d2012-03-06 07:38:00 -0500858 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000859 * @param string
860 * @param string
Andrey Andreev4c202602012-03-06 20:34:52 +0200861 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000862 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500863 public function field_exists($field_name, $table_name)
Barry Mienydd671972010-10-04 16:33:58 +0200864 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200865 return in_array($field_name, $this->list_fields($table_name));
Derek Allard2067d1a2008-11-13 22:59:24 +0000866 }
Barry Mienydd671972010-10-04 16:33:58 +0200867
Derek Allard2067d1a2008-11-13 22:59:24 +0000868 // --------------------------------------------------------------------
869
870 /**
871 * Returns an object with field data
872 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000873 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +0200874 * @return object
875 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500876 public function field_data($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000877 {
878 if ($table == '')
879 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200880 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000881 }
Barry Mienydd671972010-10-04 16:33:58 +0200882
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200883 $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE)));
Derek Allard2067d1a2008-11-13 22:59:24 +0000884 return $query->field_data();
Barry Mienydd671972010-10-04 16:33:58 +0200885 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000886
887 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200888
Derek Allard2067d1a2008-11-13 22:59:24 +0000889 /**
890 * Generate an insert string
891 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 * @param string the table upon which the query will be performed
893 * @param array an associative array data of key/values
Barry Mienydd671972010-10-04 16:33:58 +0200894 * @return string
895 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500896 public function insert_string($table, $data)
Derek Allard2067d1a2008-11-13 22:59:24 +0000897 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200898 $fields = $values = array();
Barry Mienydd671972010-10-04 16:33:58 +0200899
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500900 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000901 {
902 $fields[] = $this->_escape_identifiers($key);
903 $values[] = $this->escape($val);
904 }
Barry Mienydd671972010-10-04 16:33:58 +0200905
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200906 return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
Barry Mienydd671972010-10-04 16:33:58 +0200907 }
908
Derek Allard2067d1a2008-11-13 22:59:24 +0000909 // --------------------------------------------------------------------
910
911 /**
912 * Generate an update string
913 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000914 * @param string the table upon which the query will be performed
915 * @param array an associative array data of key/values
916 * @param mixed the "where" statement
Barry Mienydd671972010-10-04 16:33:58 +0200917 * @return string
918 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500919 public function update_string($table, $data, $where)
Derek Allard2067d1a2008-11-13 22:59:24 +0000920 {
921 if ($where == '')
922 {
Andrey Andreev4c202602012-03-06 20:34:52 +0200923 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 }
Barry Mienydd671972010-10-04 16:33:58 +0200925
Derek Allard2067d1a2008-11-13 22:59:24 +0000926 $fields = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500927 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000928 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200929 $fields[$this->protect_identifiers($key)] = $this->escape($val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000930 }
931
932 if ( ! is_array($where))
933 {
934 $dest = array($where);
935 }
936 else
937 {
938 $dest = array();
939 foreach ($where as $key => $val)
940 {
941 $prefix = (count($dest) == 0) ? '' : ' AND ';
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200942 $key = $this->protect_identifiers($key);
Barry Mienydd671972010-10-04 16:33:58 +0200943
Derek Allard2067d1a2008-11-13 22:59:24 +0000944 if ($val !== '')
945 {
946 if ( ! $this->_has_operator($key))
947 {
948 $key .= ' =';
949 }
Barry Mienydd671972010-10-04 16:33:58 +0200950
Derek Allard2067d1a2008-11-13 22:59:24 +0000951 $val = ' '.$this->escape($val);
952 }
Barry Mienydd671972010-10-04 16:33:58 +0200953
Derek Allard2067d1a2008-11-13 22:59:24 +0000954 $dest[] = $prefix.$key.$val;
955 }
Barry Mienydd671972010-10-04 16:33:58 +0200956 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000957
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200958 return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
Barry Mienydd671972010-10-04 16:33:58 +0200959 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000960
961 // --------------------------------------------------------------------
962
963 /**
964 * Tests whether the string has an SQL operator
965 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000966 * @param string
967 * @return bool
968 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500969 protected function _has_operator($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000970 {
Andrey Andreev043f2602012-03-06 20:16:42 +0200971 return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL)/i', trim($str));
Derek Allard2067d1a2008-11-13 22:59:24 +0000972 }
973
974 // --------------------------------------------------------------------
975
976 /**
977 * Enables a native PHP function to be run, using a platform agnostic wrapper.
978 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000979 * @param string the function name
980 * @param mixed any parameters needed by the function
Barry Mienydd671972010-10-04 16:33:58 +0200981 * @return mixed
982 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500983 public function call_function($function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000984 {
985 $driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
Barry Mienydd671972010-10-04 16:33:58 +0200986
Derek Allard2067d1a2008-11-13 22:59:24 +0000987 if (FALSE === strpos($driver, $function))
988 {
989 $function = $driver.$function;
990 }
Barry Mienydd671972010-10-04 16:33:58 +0200991
Derek Allard2067d1a2008-11-13 22:59:24 +0000992 if ( ! function_exists($function))
993 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200994 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000995 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000996
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200997 return (func_num_args() > 1)
998 ? call_user_func_array($function, array_splice(func_get_args(), 1))
999 : call_user_func($function);
Derek Allard2067d1a2008-11-13 22:59:24 +00001000 }
1001
1002 // --------------------------------------------------------------------
1003
1004 /**
1005 * Set Cache Directory Path
1006 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 * @param string the path to the cache directory
1008 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001009 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001010 public function cache_set_path($path = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001011 {
1012 $this->cachedir = $path;
1013 }
1014
1015 // --------------------------------------------------------------------
1016
1017 /**
1018 * Enable Query Caching
1019 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001020 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001021 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001022 public function cache_on()
Derek Allard2067d1a2008-11-13 22:59:24 +00001023 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001024 return $this->cache_on = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001025 }
1026
1027 // --------------------------------------------------------------------
1028
1029 /**
1030 * Disable Query Caching
1031 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001032 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001033 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001034 public function cache_off()
Derek Allard2067d1a2008-11-13 22:59:24 +00001035 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001036 return $this->cache_on = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001037 }
Barry Mienydd671972010-10-04 16:33:58 +02001038
Derek Allard2067d1a2008-11-13 22:59:24 +00001039
1040 // --------------------------------------------------------------------
1041
1042 /**
1043 * Delete the cache files associated with a particular URI
1044 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001045 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001046 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001047 public function cache_delete($segment_one = '', $segment_two = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001048 {
Andrey Andreev043f2602012-03-06 20:16:42 +02001049 return ($this->_cache_init())
1050 ? $this->CACHE->delete($segment_one, $segment_two)
1051 : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001052 }
1053
1054 // --------------------------------------------------------------------
1055
1056 /**
1057 * Delete All cache files
1058 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001059 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001060 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001061 public function cache_delete_all()
Derek Allard2067d1a2008-11-13 22:59:24 +00001062 {
Andrey Andreev043f2602012-03-06 20:16:42 +02001063 return ($this->_cache_init())
1064 ? $this->CACHE->delete_all()
1065 : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001066 }
1067
1068 // --------------------------------------------------------------------
1069
1070 /**
1071 * Initialize the Cache Class
1072 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001073 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001074 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001075 protected function _cache_init()
Derek Allard2067d1a2008-11-13 22:59:24 +00001076 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001077 if (class_exists('CI_DB_Cache'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001078 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001079 if (is_object($this->CACHE))
Andrey Andreev569091c2012-02-09 00:16:17 +02001080 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001081 return TRUE;
Andrey Andreev569091c2012-02-09 00:16:17 +02001082 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001083 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001084 elseif ( ! @include_once(BASEPATH.'database/DB_cache.php'))
1085 {
1086 return $this->cache_off();
1087 }
Derek Allarde37ab382009-02-03 16:13:57 +00001088
Derek Allard2067d1a2008-11-13 22:59:24 +00001089 $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
1090 return TRUE;
1091 }
1092
1093 // --------------------------------------------------------------------
1094
1095 /**
1096 * Close DB Connection
1097 *
Barry Mienydd671972010-10-04 16:33:58 +02001098 * @return void
1099 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001100 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +00001101 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001102 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +00001103 {
1104 $this->_close($this->conn_id);
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001105 $this->conn_id = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001106 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001107 }
Barry Mienydd671972010-10-04 16:33:58 +02001108
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 // --------------------------------------------------------------------
1110
1111 /**
1112 * Display an error message
1113 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001114 * @param string the error message
1115 * @param string any "swap" values
Andrey Andreev4c202602012-03-06 20:34:52 +02001116 * @param bool whether to localize the message
Barry Mienydd671972010-10-04 16:33:58 +02001117 * @return string sends the application/error_db.php template
1118 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001119 public function display_error($error = '', $swap = '', $native = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001120 {
Derek Jonese7792202010-03-02 17:24:46 -06001121 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001122 $LANG->load('db');
1123
1124 $heading = $LANG->line('db_error_heading');
1125
1126 if ($native == TRUE)
1127 {
Andrey Andreev85a99cc2011-09-24 17:17:37 +03001128 $message = (array) $error;
Derek Allard2067d1a2008-11-13 22:59:24 +00001129 }
1130 else
1131 {
1132 $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
1133 }
Barry Mienydd671972010-10-04 16:33:58 +02001134
Pascal Kriete60f8c392010-08-25 18:03:28 +02001135 // Find the most likely culprit of the error by going through
1136 // the backtrace until the source file is no longer in the
1137 // database folder.
Pascal Kriete60f8c392010-08-25 18:03:28 +02001138 $trace = debug_backtrace();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001139 foreach ($trace as $call)
Pascal Kriete60f8c392010-08-25 18:03:28 +02001140 {
1141 if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
1142 {
1143 // Found it - use a relative path for safety
1144 $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
1145 $message[] = 'Line Number: '.$call['line'];
Pascal Kriete60f8c392010-08-25 18:03:28 +02001146 break;
1147 }
1148 }
Barry Mienydd671972010-10-04 16:33:58 +02001149
Derek Jonese7792202010-03-02 17:24:46 -06001150 $error =& load_class('Exceptions', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001151 echo $error->show_error($heading, $message, 'error_db');
1152 exit;
1153 }
1154
1155 // --------------------------------------------------------------------
1156
1157 /**
1158 * Protect Identifiers
1159 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001160 * This function is used extensively by the Active Record class, and by
Barry Mienydd671972010-10-04 16:33:58 +02001161 * a couple functions in this class.
Derek Allard2067d1a2008-11-13 22:59:24 +00001162 * It takes a column or table name (optionally with an alias) and inserts
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001163 * the table prefix onto it. Some logic is necessary in order to deal with
Andrey Andreev4c202602012-03-06 20:34:52 +02001164 * column names that include the path. Consider a query like this:
Derek Allard2067d1a2008-11-13 22:59:24 +00001165 *
1166 * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
1167 *
1168 * Or a query with aliasing:
1169 *
1170 * SELECT m.member_id, m.member_name FROM members AS m
1171 *
1172 * Since the column name can include up to four segments (host, DB, table, column)
1173 * or also have an alias prefix, we need to do a bit of work to figure this out and
1174 * insert the table prefix (if it exists) in the proper position, and escape only
1175 * the correct identifiers.
1176 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001177 * @param string
1178 * @param bool
1179 * @param mixed
1180 * @param bool
1181 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001182 */
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001183 public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001184 {
1185 if ( ! is_bool($protect_identifiers))
1186 {
1187 $protect_identifiers = $this->_protect_identifiers;
1188 }
Derek Allarde37ab382009-02-03 16:13:57 +00001189
1190 if (is_array($item))
1191 {
1192 $escaped_array = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001193 foreach ($item as $k => $v)
Derek Allarde37ab382009-02-03 16:13:57 +00001194 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001195 $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v);
Derek Allarde37ab382009-02-03 16:13:57 +00001196 }
1197
1198 return $escaped_array;
1199 }
1200
Derek Allard2067d1a2008-11-13 22:59:24 +00001201 // Convert tabs or multiple spaces into single spaces
Derek Jones7b3b96c2009-02-10 21:01:47 +00001202 $item = preg_replace('/[\t ]+/', ' ', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001203
Derek Allard2067d1a2008-11-13 22:59:24 +00001204 // If the item has an alias declaration we remove it and set it aside.
1205 // Basically we remove everything to the right of the first space
Derek Allard2067d1a2008-11-13 22:59:24 +00001206 if (strpos($item, ' ') !== FALSE)
Derek Allard911d3e02008-12-15 14:08:35 +00001207 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001208 $alias = strstr($item, ' ');
Derek Allard2067d1a2008-11-13 22:59:24 +00001209 $item = substr($item, 0, - strlen($alias));
1210 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001211 else
1212 {
1213 $alias = '';
1214 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001215
Derek Allard911d3e02008-12-15 14:08:35 +00001216 // This is basically a bug fix for queries that use MAX, MIN, etc.
Barry Mienydd671972010-10-04 16:33:58 +02001217 // If a parenthesis is found we know that we do not need to
Andrey Andreev4c202602012-03-06 20:34:52 +02001218 // escape the data or add a prefix. There's probably a more graceful
Derek Allard911d3e02008-12-15 14:08:35 +00001219 // way to deal with this, but I'm not thinking of it -- Rick
1220 if (strpos($item, '(') !== FALSE)
1221 {
1222 return $item.$alias;
1223 }
1224
Derek Allard2067d1a2008-11-13 22:59:24 +00001225 // Break the string apart if it contains periods, then insert the table prefix
1226 // in the correct location, assuming the period doesn't indicate that we're dealing
1227 // with an alias. While we're at it, we will escape the components
1228 if (strpos($item, '.') !== FALSE)
1229 {
1230 $parts = explode('.', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001231
Derek Allard2067d1a2008-11-13 22:59:24 +00001232 // Does the first segment of the exploded item match
Andrey Andreev4c202602012-03-06 20:34:52 +02001233 // one of the aliases previously identified? If so,
Derek Allard2067d1a2008-11-13 22:59:24 +00001234 // we have nothing more to do other than escape the item
1235 if (in_array($parts[0], $this->ar_aliased_tables))
Derek Allard911d3e02008-12-15 14:08:35 +00001236 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001237 if ($protect_identifiers === TRUE)
1238 {
1239 foreach ($parts as $key => $val)
1240 {
1241 if ( ! in_array($val, $this->_reserved_identifiers))
1242 {
1243 $parts[$key] = $this->_escape_identifiers($val);
1244 }
1245 }
Barry Mienydd671972010-10-04 16:33:58 +02001246
Derek Allard2067d1a2008-11-13 22:59:24 +00001247 $item = implode('.', $parts);
Barry Mienydd671972010-10-04 16:33:58 +02001248 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001249
Derek Allard2067d1a2008-11-13 22:59:24 +00001250 return $item.$alias;
1251 }
Barry Mienydd671972010-10-04 16:33:58 +02001252
Andrey Andreev4c202602012-03-06 20:34:52 +02001253 // Is there a table prefix defined in the config file? If not, no need to do anything
Derek Allard2067d1a2008-11-13 22:59:24 +00001254 if ($this->dbprefix != '')
1255 {
1256 // We now add the table prefix based on some logic.
1257 // Do we have 4 segments (hostname.database.table.column)?
1258 // If so, we add the table prefix to the column name in the 3rd segment.
1259 if (isset($parts[3]))
1260 {
1261 $i = 2;
1262 }
1263 // Do we have 3 segments (database.table.column)?
1264 // If so, we add the table prefix to the column name in 2nd position
1265 elseif (isset($parts[2]))
1266 {
1267 $i = 1;
1268 }
1269 // Do we have 2 segments (table.column)?
1270 // If so, we add the table prefix to the column name in 1st segment
1271 else
1272 {
1273 $i = 0;
1274 }
Barry Mienydd671972010-10-04 16:33:58 +02001275
Derek Allard2067d1a2008-11-13 22:59:24 +00001276 // This flag is set when the supplied $item does not contain a field name.
1277 // This can happen when this function is being called from a JOIN.
1278 if ($field_exists == FALSE)
1279 {
1280 $i++;
1281 }
Barry Mienydd671972010-10-04 16:33:58 +02001282
Derek Jones55acc8b2009-07-11 03:38:13 +00001283 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001284 if ($this->swap_pre != '' && strpos($parts[$i], $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001285 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001286 $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]);
Derek Jones55acc8b2009-07-11 03:38:13 +00001287 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001288 // We only add the table prefix if it does not already exist
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001289 elseif (strpos($parts[$i], $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001290 {
1291 $parts[$i] = $this->dbprefix.$parts[$i];
1292 }
Barry Mienydd671972010-10-04 16:33:58 +02001293
Derek Allard2067d1a2008-11-13 22:59:24 +00001294 // Put the parts back together
1295 $item = implode('.', $parts);
1296 }
Barry Mienydd671972010-10-04 16:33:58 +02001297
Derek Allard2067d1a2008-11-13 22:59:24 +00001298 if ($protect_identifiers === TRUE)
1299 {
1300 $item = $this->_escape_identifiers($item);
1301 }
Barry Mienydd671972010-10-04 16:33:58 +02001302
Derek Allard2067d1a2008-11-13 22:59:24 +00001303 return $item.$alias;
1304 }
1305
Andrey Andreev4c202602012-03-06 20:34:52 +02001306 // Is there a table prefix? If not, no need to insert it
Derek Allard2067d1a2008-11-13 22:59:24 +00001307 if ($this->dbprefix != '')
1308 {
Derek Jones55acc8b2009-07-11 03:38:13 +00001309 // Verify table prefix and replace if necessary
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001310 if ($this->swap_pre != '' && strpos($item, $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001311 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001312 $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item);
Derek Jones55acc8b2009-07-11 03:38:13 +00001313 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001314 // Do we prefix an item with no segments?
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001315 elseif ($prefix_single == TRUE && strpos($item, $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001316 {
1317 $item = $this->dbprefix.$item;
Barry Mienydd671972010-10-04 16:33:58 +02001318 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001319 }
1320
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001321 if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers))
Derek Allard2067d1a2008-11-13 22:59:24 +00001322 {
1323 $item = $this->_escape_identifiers($item);
1324 }
Barry Mienydd671972010-10-04 16:33:58 +02001325
Derek Allard2067d1a2008-11-13 22:59:24 +00001326 return $item.$alias;
1327 }
Andrey Andreev4c202602012-03-06 20:34:52 +02001328
Túbal Martín511f2252011-11-24 14:43:45 +01001329 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +00001330
Túbal Martín511f2252011-11-24 14:43:45 +01001331 /**
1332 * Dummy method that allows Active Record class to be disabled
1333 *
1334 * This function is used extensively by every db driver.
1335 *
Túbal Martín511f2252011-11-24 14:43:45 +01001336 * @return void
1337 */
Timothy Warren7eeda532012-03-19 16:01:55 -04001338 abstract protected function _reset_select();
Derek Allard2067d1a2008-11-13 22:59:24 +00001339
1340}
1341
Derek Allard2067d1a2008-11-13 22:59:24 +00001342/* End of file DB_driver.php */
Timothy Warrend2ff0bc2012-03-19 16:52:10 -04001343/* Location: ./system/database/DB_driver.php */