blob: 497f8b9c9adf0c88e61832b4aa2c3f7a87520462 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * Database Driver Class
31 *
32 * This is the platform-independent base DB implementation class.
33 * This class will not be called directly. Rather, the adapter
34 * class for the specific database will extend and instantiate it.
35 *
36 * @package CodeIgniter
37 * @subpackage Drivers
38 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050039 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000040 * @link http://codeigniter.com/user_guide/database/
41 */
Timothy Warren7eeda532012-03-19 16:01:55 -040042abstract class CI_DB_driver {
Derek Allard2067d1a2008-11-13 22:59:24 +000043
Andrey Andreevae85eb42012-11-02 01:42:31 +020044 /**
45 * Data Source Name / Connect string
46 *
47 * @var string
48 */
Andrey Andreev738f5342012-03-06 20:43:40 +020049 public $dsn;
Andrey Andreevae85eb42012-11-02 01:42:31 +020050
51 /**
52 * Username
53 *
54 * @var string
55 */
Andrey Andreevd1add432012-03-06 20:26:01 +020056 public $username;
Andrey Andreevae85eb42012-11-02 01:42:31 +020057
58 /**
59 * Password
60 *
61 * @var string
62 */
Andrey Andreevd1add432012-03-06 20:26:01 +020063 public $password;
Andrey Andreevae85eb42012-11-02 01:42:31 +020064
65 /**
66 * Hostname
67 *
68 * @var string
69 */
Andrey Andreevd1add432012-03-06 20:26:01 +020070 public $hostname;
Andrey Andreevae85eb42012-11-02 01:42:31 +020071
72 /**
73 * Database name
74 *
75 * @var string
76 */
Andrey Andreevd1add432012-03-06 20:26:01 +020077 public $database;
Andrey Andreevae85eb42012-11-02 01:42:31 +020078
79 /**
80 * Database driver
81 *
82 * @var string
83 */
Andrey Andreev75546112012-07-05 11:01:29 +030084 public $dbdriver = 'mysqli';
Andrey Andreevae85eb42012-11-02 01:42:31 +020085
86 /**
87 * Sub-driver
88 *
89 * @used-by CI_DB_pdo_driver
90 * @var string
91 */
Andrey Andreevfbba54e2012-06-23 20:26:31 +030092 public $subdriver;
Andrey Andreevae85eb42012-11-02 01:42:31 +020093
94 /**
95 * Table prefix
96 *
97 * @var string
98 */
Andrey Andreevd1add432012-03-06 20:26:01 +020099 public $dbprefix = '';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200100
101 /**
102 * Character set
103 *
104 * @var string
105 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200106 public $char_set = 'utf8';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200107
108 /**
109 * Collation
110 *
111 * @var string
112 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200113 public $dbcollat = 'utf8_general_ci';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200114
115 /**
116 * Auto-init flag
117 *
118 * Whether to automatically initialize the DB connection.
119 *
120 * @var bool
121 */
122 public $autoinit = TRUE;
123
124 /**
125 * Encryption flag/data
126 *
127 * @var mixed
128 */
Andrey Andreev2f8bf9b2012-10-12 20:37:52 +0300129 public $encrypt = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200130
131 /**
132 * Swap Prefix
133 *
134 * @var string
135 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200136 public $swap_pre = '';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200137
138 /**
139 * Database port
140 *
141 * @var int
142 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200143 public $port = '';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200144
145 /**
146 * Persistent connection flag
147 *
148 * @var bool
149 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200150 public $pconnect = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200151
152 /**
153 * Connection ID
154 *
155 * @var object|resource
156 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200157 public $conn_id = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200158
159 /**
160 * Result ID
161 *
162 * @var object|resource
163 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200164 public $result_id = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200165
166 /**
167 * Debug flag
168 *
169 * Whether to display error messages.
170 *
171 * @var bool
172 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200173 public $db_debug = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200174
175 /**
176 * Benchmark time
177 *
178 * @var int
179 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200180 public $benchmark = 0;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200181
182 /**
183 * Executed queries count
184 *
185 * @var int
186 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200187 public $query_count = 0;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200188
189 /**
190 * Bind marker
191 *
192 * Character used to identify values in a prepared statement.
193 *
194 * @var string
195 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200196 public $bind_marker = '?';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200197
198 /**
199 * Save queries flag
200 *
201 * Whether to keep an in-memory history of queries for debugging purposes.
202 *
203 * @var bool
204 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200205 public $save_queries = TRUE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200206
207 /**
208 * Queries list
209 *
210 * @see CI_DB_driver::$save_queries
211 * @var string[]
212 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200213 public $queries = array();
Andrey Andreevae85eb42012-11-02 01:42:31 +0200214
215 /**
216 * Query times
217 *
218 * A list of times that queries took to execute.
219 *
220 * @var array
221 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200222 public $query_times = array();
Andrey Andreevae85eb42012-11-02 01:42:31 +0200223
224 /**
225 * Data cache
226 *
227 * An internal generic value cache.
228 *
229 * @var array
230 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200231 public $data_cache = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000232
Andrey Andreevae85eb42012-11-02 01:42:31 +0200233 /**
234 * Transaction enabled flag
235 *
236 * @var bool
237 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200238 public $trans_enabled = TRUE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200239
240 /**
241 * Strict transaction mode flag
242 *
243 * @var bool
244 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200245 public $trans_strict = TRUE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200246
247 /**
248 * Transaction depth level
249 *
250 * @var int
251 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200252 protected $_trans_depth = 0;
Derek Allard2067d1a2008-11-13 22:59:24 +0000253
Andrey Andreevae85eb42012-11-02 01:42:31 +0200254 /**
255 * Transaction status flag
256 *
257 * Used with transactions to determine if a rollback should occur.
258 *
259 * @var bool
260 */
261 protected $_trans_status = TRUE;
262
263 /**
264 * Cache On flag
265 *
266 * @var bool
267 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200268 public $cache_on = FALSE;
Andrey Andreevae85eb42012-11-02 01:42:31 +0200269
270 /**
271 * Cache directory path
272 *
273 * @var bool
274 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200275 public $cachedir = '';
Andrey Andreevae85eb42012-11-02 01:42:31 +0200276
277 /**
278 * Cache auto-delete flag
279 *
280 * @var bool
281 */
Andrey Andreevd1add432012-03-06 20:26:01 +0200282 public $cache_autodel = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200283
Andrey Andreevae85eb42012-11-02 01:42:31 +0200284 /**
285 * DB Cache object
286 *
287 * @see CI_DB_cache
288 * @var object
289 */
290 public $CACHE;
291
292 /**
293 * Protect identifiers flag
294 *
295 * @var bool
296 */
Jamie Rumbelowbcee50f2012-03-08 13:00:15 +0000297 protected $_protect_identifiers = TRUE;
Andrey Andreevd1add432012-03-06 20:26:01 +0200298
Andrey Andreevae85eb42012-11-02 01:42:31 +0200299 /**
300 * List of reserved identifiers
301 *
302 * Identifiers that must NOT be escaped.
303 *
304 * @var string[]
305 */
306 protected $_reserved_identifiers = array('*');
307
308 /**
309 * ESCAPE statement string
310 *
311 * @var string
312 */
Andrey Andreev2ea33c32012-10-04 12:37:51 +0300313 protected $_like_escape_str = " ESCAPE '%s' ";
Andrey Andreevae85eb42012-11-02 01:42:31 +0200314
315 /**
316 * ESCAPE character
317 *
318 * @var string
319 */
Andrey Andreev2ea33c32012-10-04 12:37:51 +0300320 protected $_like_escape_chr = '!';
321
Andrey Andreev75546112012-07-05 11:01:29 +0300322 /**
Andrey Andreevae85eb42012-11-02 01:42:31 +0200323 * COUNT string
324 *
325 * @used-by CI_DB_driver::count_all()
326 * @used-by CI_DB_query_builder::count_all_results()
327 *
328 * @var string
Andrey Andreev77a5d942012-07-05 15:42:14 +0300329 */
330 protected $_count_string = 'SELECT COUNT(*) AS ';
331
Andrey Andreevae85eb42012-11-02 01:42:31 +0200332 // --------------------------------------------------------------------
333
Andrey Andreev77a5d942012-07-05 15:42:14 +0300334 /**
Andrey Andreevae85eb42012-11-02 01:42:31 +0200335 * Class constructor
Andrey Andreev75546112012-07-05 11:01:29 +0300336 *
Andrey Andreevae85eb42012-11-02 01:42:31 +0200337 * @param array $params
Andrey Andreev75546112012-07-05 11:01:29 +0300338 * @return void
339 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500340 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 {
342 if (is_array($params))
343 {
344 foreach ($params as $key => $val)
345 {
346 $this->$key = $val;
347 }
348 }
349
350 log_message('debug', 'Database Driver Class Initialized');
351 }
Barry Mienydd671972010-10-04 16:33:58 +0200352
Gints Murans89f77ee2012-05-23 00:23:50 +0300353 // --------------------------------------------------------------------
Root36237d82012-05-21 18:30:00 -0400354
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 /**
356 * Initialize Database Settings
357 *
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200358 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200359 */
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200360 public function initialize()
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200362 /* If an established connection is available, then there's
363 * no need to connect and select the database.
364 *
365 * Depending on the database driver, conn_id can be either
366 * boolean TRUE, a resource or an object.
367 */
368 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 {
370 return TRUE;
371 }
Barry Mienydd671972010-10-04 16:33:58 +0200372
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 // ----------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200374
Derek Allard2067d1a2008-11-13 22:59:24 +0000375 // Connect to the database and set the connection ID
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100376 $this->conn_id = ($this->pconnect === FALSE) ? $this->db_connect() : $this->db_pconnect();
Derek Allard2067d1a2008-11-13 22:59:24 +0000377
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200378 // No connection resource? Check if there is a failover else throw an error
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 if ( ! $this->conn_id)
380 {
Felix Balfoort5d581b62011-11-29 15:53:01 +0100381 // Check if there is a failover set
382 if ( ! empty($this->failover) && is_array($this->failover))
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 {
Felix Balfoort5d581b62011-11-29 15:53:01 +0100384 // Go over all the failovers
385 foreach ($this->failover as $failover)
386 {
387 // Replace the current settings with those of the failover
388 foreach ($failover as $key => $val)
389 {
390 $this->$key = $val;
391 }
392
393 // Try to connect
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100394 $this->conn_id = ($this->pconnect === FALSE) ? $this->db_connect() : $this->db_pconnect();
Felix Balfoort5d581b62011-11-29 15:53:01 +0100395
396 // If a connection is made break the foreach loop
397 if ($this->conn_id)
398 {
399 break;
400 }
401 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 }
Felix Balfoort5d581b62011-11-29 15:53:01 +0100403
404 // We still don't have a connection?
405 if ( ! $this->conn_id)
406 {
407 log_message('error', 'Unable to connect to the database');
408
409 if ($this->db_debug)
410 {
411 $this->display_error('db_unable_to_connect');
412 }
413 return FALSE;
414 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 }
416
417 // ----------------------------------------------------------------
418
419 // Select the DB... assuming a database name is specified in the config file
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200420 if ($this->database !== '' && ! $this->db_select())
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 {
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200422 log_message('error', 'Unable to select database: '.$this->database);
Barry Mienydd671972010-10-04 16:33:58 +0200423
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200424 if ($this->db_debug)
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 {
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200426 $this->display_error('db_unable_to_select', $this->database);
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 }
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200428 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 }
430
Andrey Andreev82e8ac12012-02-22 19:35:34 +0200431 // Now we set the character set and that's all
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200432 return $this->db_set_charset($this->char_set);
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 }
Barry Mienydd671972010-10-04 16:33:58 +0200434
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 // --------------------------------------------------------------------
436
437 /**
Andrey Andreev2cae1932012-03-23 16:08:41 +0200438 * Reconnect
439 *
440 * Keep / reestablish the db connection if no queries have been
441 * sent for a length of time exceeding the server's idle timeout.
442 *
443 * This is just a dummy method to allow drivers without such
444 * functionality to not declare it, while others will override it.
445 *
446 * @return void
447 */
448 public function reconnect()
449 {
450 }
451
452 // --------------------------------------------------------------------
453
454 /**
Andrey Andreevbee66442012-03-28 15:28:19 +0300455 * Select database
456 *
457 * This is just a dummy method to allow drivers without such
458 * functionality to not declare it, while others will override it.
459 *
460 * @return bool
461 */
462 public function db_select()
463 {
464 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 }
466
467 // --------------------------------------------------------------------
468
469 /**
470 * Set client character set
471 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 * @param string
Andrey Andreev063f5962012-02-27 12:20:52 +0200473 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 */
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200475 public function db_set_charset($charset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 {
Andrey Andreev95bd1d12012-03-12 16:22:28 +0200477 if (method_exists($this, '_db_set_charset') && ! $this->_db_set_charset($charset))
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200479 log_message('error', 'Unable to set database connection charset: '.$charset);
Barry Mienydd671972010-10-04 16:33:58 +0200480
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 if ($this->db_debug)
482 {
Andrey Andreev063f5962012-02-27 12:20:52 +0200483 $this->display_error('db_unable_to_set_charset', $charset);
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 }
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 return FALSE;
487 }
Barry Mienydd671972010-10-04 16:33:58 +0200488
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 return TRUE;
490 }
Barry Mienydd671972010-10-04 16:33:58 +0200491
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 // --------------------------------------------------------------------
493
494 /**
495 * The name of the platform in use (mysql, mssql, etc...)
496 *
Barry Mienydd671972010-10-04 16:33:58 +0200497 * @return string
498 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500499 public function platform()
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 {
501 return $this->dbdriver;
502 }
503
504 // --------------------------------------------------------------------
505
506 /**
Andrey Andreev08856b82012-03-03 03:19:28 +0200507 * Database version number
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 *
Andrey Andreev08856b82012-03-03 03:19:28 +0200509 * Returns a string containing the version of the database being used.
510 * Most drivers will override this method.
511 *
Barry Mienydd671972010-10-04 16:33:58 +0200512 * @return string
513 */
Andrey Andreev08856b82012-03-03 03:19:28 +0200514 public function version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200516 if (isset($this->data_cache['version']))
517 {
518 return $this->data_cache['version'];
519 }
520
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 if (FALSE === ($sql = $this->_version()))
522 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200523 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 }
Derek Allard3683f772009-12-16 17:32:33 +0000525
Andrey Andreev08856b82012-03-03 03:19:28 +0200526 $query = $this->query($sql);
527 $query = $query->row();
528 return $this->data_cache['version'] = $query->ver;
529 }
Derek Allard3683f772009-12-16 17:32:33 +0000530
Andrey Andreev08856b82012-03-03 03:19:28 +0200531 // --------------------------------------------------------------------
532
533 /**
534 * Version number query string
535 *
536 * @return string
537 */
538 protected function _version()
539 {
540 return 'SELECT VERSION() AS ver';
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 }
Barry Mienydd671972010-10-04 16:33:58 +0200542
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 // --------------------------------------------------------------------
544
545 /**
546 * Execute the query
547 *
548 * Accepts an SQL string as input and returns a result object upon
Andrey Andreev4c202602012-03-06 20:34:52 +0200549 * successful execution of a "read" type query. Returns boolean TRUE
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 * upon successful execution of a "write" type query. Returns boolean
551 * FALSE upon failure, and if the $db_debug variable is set to TRUE
552 * will raise an error.
553 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300554 * @param string $sql
555 * @param array $binds = FALSE An array of binding data
556 * @param bool $return_object = NULL
Barry Mienydd671972010-10-04 16:33:58 +0200557 * @return mixed
558 */
Andrey Andreevb66664b2012-06-27 14:22:10 +0300559 public function query($sql, $binds = FALSE, $return_object = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 {
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100561 if ($sql === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000562 {
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200563 log_message('error', 'Invalid query: '.$sql);
564
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200565 return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000566 }
Andrey Andreevb66664b2012-06-27 14:22:10 +0300567 elseif ( ! is_bool($return_object))
568 {
569 $return_object = ! $this->is_write_type($sql);
570 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000571
572 // Verify table prefix and replace if necessary
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100573 if ($this->dbprefix !== '' && $this->swap_pre !== '' && $this->dbprefix !== $this->swap_pre)
Derek Jonese7792202010-03-02 17:24:46 -0600574 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200575 $sql = preg_replace('/(\W)'.$this->swap_pre.'(\S+?)/', '\\1'.$this->dbprefix.'\\2', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 }
Derek Jonese7792202010-03-02 17:24:46 -0600577
Ryan Dialef7474c2012-03-01 16:11:36 -0500578 // Compile binds if needed
579 if ($binds !== FALSE)
580 {
581 $sql = $this->compile_binds($sql, $binds);
582 }
583
Andrey Andreev4c202602012-03-06 20:34:52 +0200584 // Is query caching enabled? If the query is a "read type"
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 // we will load the caching class and return the previously
586 // cached query if it exists
Andrey Andreevb66664b2012-06-27 14:22:10 +0300587 if ($this->cache_on === TRUE && $return_object === TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200589 $this->load_rdriver();
590 if (FALSE !== ($cache = $this->CACHE->read($sql)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200592 return $cache;
Derek Allard2067d1a2008-11-13 22:59:24 +0000593 }
594 }
Barry Mienydd671972010-10-04 16:33:58 +0200595
Andrey Andreevb66664b2012-06-27 14:22:10 +0300596 // Save the query for debugging
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100597 if ($this->save_queries === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000598 {
599 $this->queries[] = $sql;
600 }
Barry Mienydd671972010-10-04 16:33:58 +0200601
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 // Start the Query Timer
dixyab3cab52012-04-21 00:58:00 +0200603 $time_start = microtime(TRUE);
Barry Mienydd671972010-10-04 16:33:58 +0200604
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 // Run the Query
606 if (FALSE === ($this->result_id = $this->simple_query($sql)))
607 {
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100608 if ($this->save_queries === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 {
610 $this->query_times[] = 0;
611 }
Barry Mienydd671972010-10-04 16:33:58 +0200612
Derek Allard2067d1a2008-11-13 22:59:24 +0000613 // This will trigger a rollback if transactions are being used
614 $this->_trans_status = FALSE;
615
Andrey Andreev4be5de12012-03-02 15:45:41 +0200616 // Grab the error now, as we might run some additional queries before displaying the error
617 $error = $this->error();
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200618
619 // Log errors
Andrey Andreevb66664b2012-06-27 14:22:10 +0300620 log_message('error', 'Query error: '.$error['message'].' - Invalid query: '.$sql);
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200621
Derek Allard2067d1a2008-11-13 22:59:24 +0000622 if ($this->db_debug)
623 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000624 // We call this function in order to roll-back queries
Andrey Andreev4be5de12012-03-02 15:45:41 +0200625 // if transactions are enabled. If we don't call this here
Barry Mienydd671972010-10-04 16:33:58 +0200626 // the error message will trigger an exit, causing the
Derek Allard2067d1a2008-11-13 22:59:24 +0000627 // transactions to remain in limbo.
628 $this->trans_complete();
629
Niklas Nilssond2018ee2011-08-30 13:39:42 +0200630 // Display errors
Andrey Andreev27984582012-03-03 04:43:10 +0200631 return $this->display_error(array('Error Number: '.$error['code'], $error['message'], $sql));
Derek Allard2067d1a2008-11-13 22:59:24 +0000632 }
Barry Mienydd671972010-10-04 16:33:58 +0200633
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 return FALSE;
635 }
Barry Mienydd671972010-10-04 16:33:58 +0200636
Derek Allard2067d1a2008-11-13 22:59:24 +0000637 // Stop and aggregate the query time results
dixyab3cab52012-04-21 00:58:00 +0200638 $time_end = microtime(TRUE);
639 $this->benchmark += $time_end - $time_start;
Derek Allard2067d1a2008-11-13 22:59:24 +0000640
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100641 if ($this->save_queries === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 {
dixyab3cab52012-04-21 00:58:00 +0200643 $this->query_times[] = $time_end - $time_start;
Derek Allard2067d1a2008-11-13 22:59:24 +0000644 }
Barry Mienydd671972010-10-04 16:33:58 +0200645
Derek Allard2067d1a2008-11-13 22:59:24 +0000646 // Increment the query counter
647 $this->query_count++;
Barry Mienydd671972010-10-04 16:33:58 +0200648
Andrey Andreevb66664b2012-06-27 14:22:10 +0300649 // Will we have a result object instantiated? If not - we'll simply return TRUE
650 if ($return_object !== TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000651 {
Andrey Andreevb66664b2012-06-27 14:22:10 +0300652 // If caching is enabled we'll auto-cleanup any existing files related to this particular URI
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100653 if ($this->cache_on === TRUE && $this->cache_autodel === TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000654 {
655 $this->CACHE->delete();
656 }
Barry Mienydd671972010-10-04 16:33:58 +0200657
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 return TRUE;
659 }
Barry Mienydd671972010-10-04 16:33:58 +0200660
Derek Allard2067d1a2008-11-13 22:59:24 +0000661 // Return TRUE if we don't need to create a result object
Derek Allard2067d1a2008-11-13 22:59:24 +0000662 if ($return_object !== TRUE)
663 {
664 return TRUE;
665 }
Barry Mienydd671972010-10-04 16:33:58 +0200666
667 // Load and instantiate the result driver
Andrey Andreev57bdeb62012-03-05 15:59:16 +0200668 $driver = $this->load_rdriver();
669 $RES = new $driver($this);
Barry Mienydd671972010-10-04 16:33:58 +0200670
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200671 // Is query caching enabled? If so, we'll serialize the
Derek Allard2067d1a2008-11-13 22:59:24 +0000672 // result object and save it to a cache file.
Alex Bilbie48a2baf2012-06-02 11:09:54 +0100673 if ($this->cache_on === TRUE && $this->_cache_init())
Derek Allard2067d1a2008-11-13 22:59:24 +0000674 {
675 // We'll create a new instance of the result object
676 // only without the platform specific driver since
677 // we can't use it with cached data (the query result
678 // resource ID won't be any good once we've cached the
679 // result object, so we'll have to compile the data
680 // and save it)
681 $CR = new CI_DB_result();
Derek Allard2067d1a2008-11-13 22:59:24 +0000682 $CR->result_object = $RES->result_object();
683 $CR->result_array = $RES->result_array();
Andrey Andreev24abcb92012-01-05 20:40:15 +0200684 $CR->num_rows = $RES->num_rows();
Barry Mienydd671972010-10-04 16:33:58 +0200685
Derek Allard2067d1a2008-11-13 22:59:24 +0000686 // Reset these since cached objects can not utilize resource IDs.
687 $CR->conn_id = NULL;
688 $CR->result_id = NULL;
689
690 $this->CACHE->write($sql, $CR);
691 }
Barry Mienydd671972010-10-04 16:33:58 +0200692
Derek Allard2067d1a2008-11-13 22:59:24 +0000693 return $RES;
694 }
695
696 // --------------------------------------------------------------------
697
698 /**
699 * Load the result drivers
700 *
Barry Mienydd671972010-10-04 16:33:58 +0200701 * @return string the name of the result class
702 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500703 public function load_rdriver()
Derek Allard2067d1a2008-11-13 22:59:24 +0000704 {
705 $driver = 'CI_DB_'.$this->dbdriver.'_result';
706
707 if ( ! class_exists($driver))
708 {
Greg Aker3a746652011-04-19 10:59:47 -0500709 include_once(BASEPATH.'database/DB_result.php');
710 include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000711 }
Barry Mienydd671972010-10-04 16:33:58 +0200712
Derek Allard2067d1a2008-11-13 22:59:24 +0000713 return $driver;
714 }
Barry Mienydd671972010-10-04 16:33:58 +0200715
Derek Allard2067d1a2008-11-13 22:59:24 +0000716 // --------------------------------------------------------------------
717
718 /**
719 * Simple Query
Andrey Andreev4c202602012-03-06 20:34:52 +0200720 * This is a simplified version of the query() function. Internally
Derek Allard2067d1a2008-11-13 22:59:24 +0000721 * we only use it when running transaction commands since they do
722 * not require all the features of the main query() function.
723 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000724 * @param string the sql query
Barry Mienydd671972010-10-04 16:33:58 +0200725 * @return mixed
726 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500727 public function simple_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000728 {
729 if ( ! $this->conn_id)
730 {
731 $this->initialize();
732 }
733
734 return $this->_execute($sql);
735 }
Barry Mienydd671972010-10-04 16:33:58 +0200736
Derek Allard2067d1a2008-11-13 22:59:24 +0000737 // --------------------------------------------------------------------
738
739 /**
740 * Disable Transactions
741 * This permits transactions to be disabled at run-time.
742 *
Barry Mienydd671972010-10-04 16:33:58 +0200743 * @return void
744 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500745 public function trans_off()
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 {
747 $this->trans_enabled = FALSE;
748 }
749
750 // --------------------------------------------------------------------
751
752 /**
753 * Enable/disable Transaction Strict Mode
754 * When strict mode is enabled, if you are running multiple groups of
755 * transactions, if one group fails all groups will be rolled back.
756 * If strict mode is disabled, each group is treated autonomously, meaning
757 * a failure of one group will not affect any others
758 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300759 * @param bool $mode = TRUE
Barry Mienydd671972010-10-04 16:33:58 +0200760 * @return void
761 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500762 public function trans_strict($mode = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000763 {
764 $this->trans_strict = is_bool($mode) ? $mode : TRUE;
765 }
Barry Mienydd671972010-10-04 16:33:58 +0200766
Derek Allard2067d1a2008-11-13 22:59:24 +0000767 // --------------------------------------------------------------------
768
769 /**
770 * Start Transaction
771 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300772 * @param bool $test_mode = FALSE
Barry Mienydd671972010-10-04 16:33:58 +0200773 * @return void
774 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500775 public function trans_start($test_mode = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200776 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000777 if ( ! $this->trans_enabled)
778 {
779 return FALSE;
780 }
781
782 // When transactions are nested we only begin/commit/rollback the outermost ones
783 if ($this->_trans_depth > 0)
784 {
785 $this->_trans_depth += 1;
786 return;
787 }
Barry Mienydd671972010-10-04 16:33:58 +0200788
Derek Allard2067d1a2008-11-13 22:59:24 +0000789 $this->trans_begin($test_mode);
Jacob Terry07fcedf2011-11-22 11:21:36 -0500790 $this->_trans_depth += 1;
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 }
792
793 // --------------------------------------------------------------------
794
795 /**
796 * Complete Transaction
797 *
Barry Mienydd671972010-10-04 16:33:58 +0200798 * @return bool
799 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500800 public function trans_complete()
Derek Allard2067d1a2008-11-13 22:59:24 +0000801 {
802 if ( ! $this->trans_enabled)
803 {
804 return FALSE;
805 }
Barry Mienydd671972010-10-04 16:33:58 +0200806
Derek Allard2067d1a2008-11-13 22:59:24 +0000807 // When transactions are nested we only begin/commit/rollback the outermost ones
808 if ($this->_trans_depth > 1)
809 {
810 $this->_trans_depth -= 1;
811 return TRUE;
812 }
Jacob Terry07fcedf2011-11-22 11:21:36 -0500813 else
814 {
815 $this->_trans_depth = 0;
816 }
Barry Mienydd671972010-10-04 16:33:58 +0200817
Derek Allard2067d1a2008-11-13 22:59:24 +0000818 // The query() function will set this flag to FALSE in the event that a query failed
819 if ($this->_trans_status === FALSE)
820 {
821 $this->trans_rollback();
Barry Mienydd671972010-10-04 16:33:58 +0200822
Derek Allard2067d1a2008-11-13 22:59:24 +0000823 // If we are NOT running in strict mode, we will reset
824 // the _trans_status flag so that subsequent groups of transactions
825 // will be permitted.
826 if ($this->trans_strict === FALSE)
827 {
828 $this->_trans_status = TRUE;
829 }
830
831 log_message('debug', 'DB Transaction Failure');
832 return FALSE;
833 }
Barry Mienydd671972010-10-04 16:33:58 +0200834
Derek Allard2067d1a2008-11-13 22:59:24 +0000835 $this->trans_commit();
836 return TRUE;
837 }
838
839 // --------------------------------------------------------------------
840
841 /**
842 * Lets you retrieve the transaction flag to determine if it has failed
843 *
Barry Mienydd671972010-10-04 16:33:58 +0200844 * @return bool
845 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500846 public function trans_status()
Derek Allard2067d1a2008-11-13 22:59:24 +0000847 {
848 return $this->_trans_status;
849 }
850
851 // --------------------------------------------------------------------
852
853 /**
854 * Compile Bindings
855 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000856 * @param string the sql statement
857 * @param array an array of bind data
Barry Mienydd671972010-10-04 16:33:58 +0200858 * @return string
859 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500860 public function compile_binds($sql, $binds)
Derek Allard2067d1a2008-11-13 22:59:24 +0000861 {
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300862 if (empty($binds) OR empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000863 {
864 return $sql;
865 }
Andrey Andreev4e9538f2012-06-12 14:16:53 +0300866 elseif ( ! is_array($binds))
Derek Allard2067d1a2008-11-13 22:59:24 +0000867 {
Andrey Andreevaf915ce2012-06-13 19:03:06 +0300868 $binds = array($binds);
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300869 $bind_count = 1;
Derek Allard2067d1a2008-11-13 22:59:24 +0000870 }
Andrey Andreev4e9538f2012-06-12 14:16:53 +0300871 else
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200872 {
Andrey Andreev4e9538f2012-06-12 14:16:53 +0300873 // Make sure we're using numeric keys
874 $binds = array_values($binds);
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300875 $bind_count = count($binds);
Derek Allard2067d1a2008-11-13 22:59:24 +0000876 }
877
Andrey Andreevaf915ce2012-06-13 19:03:06 +0300878 // We'll need the marker length later
879 $ml = strlen($this->bind_marker);
880
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300881 // Make sure not to replace a chunk inside a string that happens to match the bind marker
882 if ($c = preg_match_all("/'[^']*'/i", $sql, $matches))
Derek Allard2067d1a2008-11-13 22:59:24 +0000883 {
Andrey Andreeve4742582012-10-25 13:25:13 +0300884 $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i',
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300885 str_replace($matches[0],
886 str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]),
887 $sql, $c),
888 $matches, PREG_OFFSET_CAPTURE);
889
890 // Bind values' count must match the count of markers in the query
891 if ($bind_count !== $c)
892 {
893 return $sql;
894 }
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300895 }
Andrey Andreeve4742582012-10-25 13:25:13 +0300896 elseif (($c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bind_count)
Andrey Andreev10cbdf02012-06-13 13:32:30 +0300897 {
Andrey Andreevaf915ce2012-06-13 19:03:06 +0300898 return $sql;
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 }
900
Andrey Andreevaf915ce2012-06-13 19:03:06 +0300901 do
902 {
903 $c--;
904 $sql = substr_replace($sql, $this->escape($binds[$c]), $matches[0][$c][1], $ml);
905 }
906 while ($c !== 0);
907
Andrey Andreev4e9538f2012-06-12 14:16:53 +0300908 return $sql;
Derek Allard2067d1a2008-11-13 22:59:24 +0000909 }
Barry Mienydd671972010-10-04 16:33:58 +0200910
Derek Allard2067d1a2008-11-13 22:59:24 +0000911 // --------------------------------------------------------------------
912
913 /**
914 * Determines if a query is a "write" type.
915 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 * @param string An SQL query string
Andrey Andreev67f71a42012-03-01 16:18:42 +0200917 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200918 */
Andrey Andreev67f71a42012-03-01 16:18:42 +0200919 public function is_write_type($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000920 {
Andrey Andreev9e31f8f2012-10-05 17:31:46 +0300921 return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000922 }
Barry Mienydd671972010-10-04 16:33:58 +0200923
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 // --------------------------------------------------------------------
925
926 /**
927 * Calculate the aggregate query elapsed time
928 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200929 * @param int The number of decimal places
930 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200931 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500932 public function elapsed_time($decimals = 6)
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 {
934 return number_format($this->benchmark, $decimals);
935 }
Barry Mienydd671972010-10-04 16:33:58 +0200936
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 // --------------------------------------------------------------------
938
939 /**
940 * Returns the total number of queries
941 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200942 * @return int
Barry Mienydd671972010-10-04 16:33:58 +0200943 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500944 public function total_queries()
Derek Allard2067d1a2008-11-13 22:59:24 +0000945 {
946 return $this->query_count;
947 }
Barry Mienydd671972010-10-04 16:33:58 +0200948
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 // --------------------------------------------------------------------
950
951 /**
952 * Returns the last query that was executed
953 *
Andrey Andreev4c202602012-03-06 20:34:52 +0200954 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200955 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500956 public function last_query()
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 {
958 return end($this->queries);
959 }
960
961 // --------------------------------------------------------------------
962
963 /**
964 * "Smart" Escape String
965 *
966 * Escapes data based on type
967 * Sets boolean and null types
968 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000969 * @param string
Barry Mienydd671972010-10-04 16:33:58 +0200970 * @return mixed
971 */
Timothy Warrene45518d2012-03-06 07:38:00 -0500972 public function escape($str)
Barry Mienydd671972010-10-04 16:33:58 +0200973 {
Joel Kallman10aa8e62012-03-09 14:54:53 -0500974 if (is_string($str) OR method_exists($str, '__toString'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000975 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200976 return "'".$this->escape_str($str)."'";
Derek Jonesa377bdd2009-02-11 18:55:24 +0000977 }
978 elseif (is_bool($str))
979 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200980 return ($str === FALSE) ? 0 : 1;
Derek Jonesa377bdd2009-02-11 18:55:24 +0000981 }
982 elseif (is_null($str))
983 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +0200984 return 'NULL';
Derek Jonesa377bdd2009-02-11 18:55:24 +0000985 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000986
987 return $str;
988 }
989
990 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -0600991
Derek Jonese4ed5832009-02-20 21:44:59 +0000992 /**
Derek Jonesbdc7fb92009-02-20 21:55:10 +0000993 * Escape LIKE String
Derek Jonese4ed5832009-02-20 21:44:59 +0000994 *
995 * Calls the individual driver for platform
996 * specific escaping for LIKE conditions
Barry Mienydd671972010-10-04 16:33:58 +0200997 *
Derek Jonese4ed5832009-02-20 21:44:59 +0000998 * @param string
999 * @return mixed
1000 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001001 public function escape_like_str($str)
Barry Mienydd671972010-10-04 16:33:58 +02001002 {
1003 return $this->escape_str($str, TRUE);
Derek Jonese4ed5832009-02-20 21:44:59 +00001004 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001005
Derek Jonese4ed5832009-02-20 21:44:59 +00001006 // --------------------------------------------------------------------
Derek Jonese7792202010-03-02 17:24:46 -06001007
Derek Allard2067d1a2008-11-13 22:59:24 +00001008 /**
1009 * Primary
1010 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001011 * Retrieves the primary key. It assumes that the row in the first
Derek Allard2067d1a2008-11-13 22:59:24 +00001012 * position is the primary key
1013 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001014 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +02001015 * @return string
1016 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001017 public function primary($table = '')
Barry Mienydd671972010-10-04 16:33:58 +02001018 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001019 $fields = $this->list_fields($table);
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001020 return is_array($fields) ? current($fields) : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001021 }
1022
1023 // --------------------------------------------------------------------
1024
1025 /**
Andrey Andreev16bb9bd2012-05-26 18:21:14 +03001026 * "Count All" query
1027 *
1028 * Generates a platform-specific query string that counts all records in
1029 * the specified database
1030 *
1031 * @param string
1032 * @return int
1033 */
1034 public function count_all($table = '')
1035 {
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001036 if ($table === '')
Andrey Andreev16bb9bd2012-05-26 18:21:14 +03001037 {
1038 return 0;
1039 }
1040
1041 $query = $this->query($this->_count_string.$this->escape_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001042 if ($query->num_rows() === 0)
Andrey Andreev16bb9bd2012-05-26 18:21:14 +03001043 {
1044 return 0;
1045 }
1046
1047 $query = $query->row();
1048 $this->_reset_select();
1049 return (int) $query->numrows;
1050 }
1051
1052 // --------------------------------------------------------------------
1053
1054 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001055 * Returns an array of table names
1056 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001057 * @param string $constrain_by_prefix = FALSE
Barry Mienydd671972010-10-04 16:33:58 +02001058 * @return array
1059 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001060 public function list_tables($constrain_by_prefix = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001061 {
1062 // Is there a cached result?
1063 if (isset($this->data_cache['table_names']))
1064 {
1065 return $this->data_cache['table_names'];
1066 }
Barry Mienydd671972010-10-04 16:33:58 +02001067
Derek Allard2067d1a2008-11-13 22:59:24 +00001068 if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix)))
1069 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001070 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001071 }
1072
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001073 $this->data_cache['table_names'] = array();
Derek Allard2067d1a2008-11-13 22:59:24 +00001074 $query = $this->query($sql);
Barry Mienydd671972010-10-04 16:33:58 +02001075
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001076 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +00001077 {
Andrey Andreev12567e82012-01-25 22:50:33 +02001078 // Do we know from which column to get the table name?
1079 if ( ! isset($key))
Derek Allard2067d1a2008-11-13 22:59:24 +00001080 {
Andrey Andreev6781a5f2012-03-28 14:50:51 +03001081 if (isset($row['table_name']))
Andrey Andreev12567e82012-01-25 22:50:33 +02001082 {
1083 $key = 'table_name';
1084 }
Andrey Andreev6781a5f2012-03-28 14:50:51 +03001085 elseif (isset($row['TABLE_NAME']))
Andrey Andreev12567e82012-01-25 22:50:33 +02001086 {
1087 $key = 'TABLE_NAME';
1088 }
1089 else
1090 {
1091 /* We have no other choice but to just get the first element's key.
1092 * Due to array_shift() accepting it's argument by reference, if
1093 * E_STRICT is on, this would trigger a warning. So we'll have to
1094 * assign it first.
1095 */
1096 $key = array_keys($row);
1097 $key = array_shift($key);
1098 }
Taufan Aditya18209332012-02-09 16:07:27 +07001099 }
1100
Andrey Andreev12567e82012-01-25 22:50:33 +02001101 $this->data_cache['table_names'][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +00001102 }
1103
Derek Allard2067d1a2008-11-13 22:59:24 +00001104 return $this->data_cache['table_names'];
1105 }
Barry Mienydd671972010-10-04 16:33:58 +02001106
Derek Allard2067d1a2008-11-13 22:59:24 +00001107 // --------------------------------------------------------------------
1108
1109 /**
1110 * Determine if a particular table exists
Timothy Warrene45518d2012-03-06 07:38:00 -05001111 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001112 * @param string $table_name
Andrey Andreev4c202602012-03-06 20:34:52 +02001113 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001114 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001115 public function table_exists($table_name)
Barry Mienydd671972010-10-04 16:33:58 +02001116 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001117 return in_array($this->protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables());
Derek Allard2067d1a2008-11-13 22:59:24 +00001118 }
Barry Mienydd671972010-10-04 16:33:58 +02001119
Derek Allard2067d1a2008-11-13 22:59:24 +00001120 // --------------------------------------------------------------------
1121
1122 /**
Andrey Andreev75546112012-07-05 11:01:29 +03001123 * Fetch Field Names
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001125 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +02001126 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +00001127 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001128 public function list_fields($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001129 {
1130 // Is there a cached result?
1131 if (isset($this->data_cache['field_names'][$table]))
1132 {
1133 return $this->data_cache['field_names'][$table];
1134 }
Barry Mienydd671972010-10-04 16:33:58 +02001135
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001136 if ($table === '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001137 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001138 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001139 }
Barry Mienydd671972010-10-04 16:33:58 +02001140
Greg Aker1edde302010-01-26 00:17:01 +00001141 if (FALSE === ($sql = $this->_list_columns($table)))
Derek Allard2067d1a2008-11-13 22:59:24 +00001142 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001143 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001144 }
Barry Mienydd671972010-10-04 16:33:58 +02001145
Derek Allard2067d1a2008-11-13 22:59:24 +00001146 $query = $this->query($sql);
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001147 $this->data_cache['field_names'][$table] = array();
Barry Mienydd671972010-10-04 16:33:58 +02001148
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001149 foreach ($query->result_array() as $row)
Derek Allard2067d1a2008-11-13 22:59:24 +00001150 {
Andrey Andreev12567e82012-01-25 22:50:33 +02001151 // Do we know from where to get the column's name?
1152 if ( ! isset($key))
Derek Allard2067d1a2008-11-13 22:59:24 +00001153 {
Andrey Andreev6781a5f2012-03-28 14:50:51 +03001154 if (isset($row['column_name']))
Andrey Andreev12567e82012-01-25 22:50:33 +02001155 {
1156 $key = 'column_name';
1157 }
Andrey Andreev6781a5f2012-03-28 14:50:51 +03001158 elseif (isset($row['COLUMN_NAME']))
Andrey Andreev12567e82012-01-25 22:50:33 +02001159 {
1160 $key = 'COLUMN_NAME';
1161 }
1162 else
1163 {
1164 /* We have no other choice but to just get the first element's key.
1165 * Due to array_shift() accepting it's argument by reference, if
1166 * E_STRICT is on, this would trigger a warning. So we'll have to
1167 * assign it first.
1168 */
1169 $key = array_keys($row);
1170 $key = array_shift($key);
1171 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001172 }
Andrey Andreev12567e82012-01-25 22:50:33 +02001173
1174 $this->data_cache['field_names'][$table][] = $row[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +00001175 }
Barry Mienydd671972010-10-04 16:33:58 +02001176
Derek Allard2067d1a2008-11-13 22:59:24 +00001177 return $this->data_cache['field_names'][$table];
1178 }
1179
1180 // --------------------------------------------------------------------
1181
1182 /**
1183 * Determine if a particular field exists
Timothy Warrene45518d2012-03-06 07:38:00 -05001184 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001185 * @param string
1186 * @param string
Andrey Andreev4c202602012-03-06 20:34:52 +02001187 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001188 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001189 public function field_exists($field_name, $table_name)
Barry Mienydd671972010-10-04 16:33:58 +02001190 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001191 return in_array($field_name, $this->list_fields($table_name));
Derek Allard2067d1a2008-11-13 22:59:24 +00001192 }
Barry Mienydd671972010-10-04 16:33:58 +02001193
Derek Allard2067d1a2008-11-13 22:59:24 +00001194 // --------------------------------------------------------------------
1195
1196 /**
1197 * Returns an object with field data
1198 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001199 * @param string the table name
Barry Mienydd671972010-10-04 16:33:58 +02001200 * @return object
1201 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001202 public function field_data($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001203 {
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001204 if ($table === '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001205 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001206 return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001207 }
Barry Mienydd671972010-10-04 16:33:58 +02001208
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001209 $query = $this->query($this->_field_data($this->protect_identifiers($table, TRUE, NULL, FALSE)));
Derek Allard2067d1a2008-11-13 22:59:24 +00001210 return $query->field_data();
Barry Mienydd671972010-10-04 16:33:58 +02001211 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001212
1213 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001214
Derek Allard2067d1a2008-11-13 22:59:24 +00001215 /**
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001216 * Escape the SQL Identifiers
1217 *
1218 * This function escapes column and table names
1219 *
Andrey Andreev9637b402012-06-08 15:39:24 +03001220 * @param mixed
1221 * @return mixed
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001222 */
1223 public function escape_identifiers($item)
1224 {
Andrey Andreev49aa45b2012-07-06 16:22:21 +03001225 if ($this->_escape_char === '' OR empty($item))
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001226 {
1227 return $item;
1228 }
Andrey Andreev9637b402012-06-08 15:39:24 +03001229 elseif (is_array($item))
1230 {
1231 foreach ($item as $key => $value)
1232 {
1233 $item[$key] = $this->escape_identifiers($value);
1234 }
1235
1236 return $item;
1237 }
Andrey Andreev49aa45b2012-07-06 16:22:21 +03001238 // Avoid breaking functions and literal values inside queries
Andrey Andreev9859cb02012-07-13 13:07:58 +03001239 elseif (ctype_digit($item) OR $item[0] === "'" OR ($this->_escape_char !== '"' && $item[0] === '"') OR strpos($item, '(') !== FALSE)
Andrey Andreev7db0f592012-06-28 17:54:27 +03001240 {
1241 return $item;
1242 }
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001243
Andrey Andreev082ee2b2012-06-08 15:26:34 +03001244 static $preg_ec = array();
1245
1246 if (empty($preg_ec))
1247 {
1248 if (is_array($this->_escape_char))
1249 {
Andrey Andreev2636c1c2012-07-02 14:53:39 +03001250 $preg_ec = array(
Andrey Andreeve4742582012-10-25 13:25:13 +03001251 preg_quote($this->_escape_char[0], '/'), preg_quote($this->_escape_char[1], '/'),
Andrey Andreev2636c1c2012-07-02 14:53:39 +03001252 $this->_escape_char[0], $this->_escape_char[1]
1253 );
Andrey Andreev082ee2b2012-06-08 15:26:34 +03001254 }
1255 else
1256 {
Andrey Andreeve4742582012-10-25 13:25:13 +03001257 $preg_ec[0] = $preg_ec[1] = preg_quote($this->_escape_char, '/');
Andrey Andreev2636c1c2012-07-02 14:53:39 +03001258 $preg_ec[2] = $preg_ec[3] = $this->_escape_char;
Andrey Andreev082ee2b2012-06-08 15:26:34 +03001259 }
1260 }
1261
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001262 foreach ($this->_reserved_identifiers as $id)
1263 {
1264 if (strpos($item, '.'.$id) !== FALSE)
1265 {
Andrey Andreev2636c1c2012-07-02 14:53:39 +03001266 return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?\./i', $preg_ec[2].'$1'.$preg_ec[3].'.', $item);
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001267 }
1268 }
1269
Andrey Andreev2636c1c2012-07-02 14:53:39 +03001270 return preg_replace('/'.$preg_ec[0].'?([^'.$preg_ec[1].'\.]+)'.$preg_ec[1].'?(\.)?/i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001271 }
1272
1273 // --------------------------------------------------------------------
1274
1275 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001276 * Generate an insert string
1277 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001278 * @param string the table upon which the query will be performed
1279 * @param array an associative array data of key/values
Barry Mienydd671972010-10-04 16:33:58 +02001280 * @return string
1281 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001282 public function insert_string($table, $data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001283 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001284 $fields = $values = array();
Barry Mienydd671972010-10-04 16:33:58 +02001285
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001286 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001287 {
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001288 $fields[] = $this->escape_identifiers($key);
Derek Allard2067d1a2008-11-13 22:59:24 +00001289 $values[] = $this->escape($val);
1290 }
Barry Mienydd671972010-10-04 16:33:58 +02001291
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001292 return $this->_insert($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
Barry Mienydd671972010-10-04 16:33:58 +02001293 }
1294
Derek Allard2067d1a2008-11-13 22:59:24 +00001295 // --------------------------------------------------------------------
1296
1297 /**
Andrey Andreev75546112012-07-05 11:01:29 +03001298 * Insert statement
1299 *
1300 * Generates a platform-specific insert string from the supplied data
1301 *
1302 * @param string the table name
1303 * @param array the insert keys
1304 * @param array the insert values
1305 * @return string
1306 */
1307 protected function _insert($table, $keys, $values)
1308 {
1309 return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
1310 }
1311
1312 // --------------------------------------------------------------------
1313
1314 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001315 * Generate an update string
1316 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001317 * @param string the table upon which the query will be performed
1318 * @param array an associative array data of key/values
1319 * @param mixed the "where" statement
Barry Mienydd671972010-10-04 16:33:58 +02001320 * @return string
1321 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001322 public function update_string($table, $data, $where)
Derek Allard2067d1a2008-11-13 22:59:24 +00001323 {
Andrey Andreev87f4dc22012-11-01 01:11:22 +02001324 if (empty($where))
Derek Allard2067d1a2008-11-13 22:59:24 +00001325 {
Andrey Andreev4c202602012-03-06 20:34:52 +02001326 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001327 }
Barry Mienydd671972010-10-04 16:33:58 +02001328
Andrey Andreev87f4dc22012-11-01 01:11:22 +02001329 $this->where($where);
1330
Derek Allard2067d1a2008-11-13 22:59:24 +00001331 $fields = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001332 foreach ($data as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001333 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001334 $fields[$this->protect_identifiers($key)] = $this->escape($val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001335 }
1336
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001337 return $this->_update($this->protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
Barry Mienydd671972010-10-04 16:33:58 +02001338 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001339
1340 // --------------------------------------------------------------------
1341
1342 /**
Andrey Andreev75546112012-07-05 11:01:29 +03001343 * Update statement
1344 *
1345 * Generates a platform-specific update string from the supplied data
1346 *
1347 * @param string the table name
Andrey Andreev822317b2012-07-19 16:00:32 +03001348 * @param array the update data
Andrey Andreev75546112012-07-05 11:01:29 +03001349 * @return string
1350 */
Andrey Andreevb0478652012-07-18 15:34:46 +03001351 protected function _update($table, $values)
Andrey Andreev75546112012-07-05 11:01:29 +03001352 {
1353 foreach ($values as $key => $val)
1354 {
1355 $valstr[] = $key.' = '.$val;
1356 }
1357
Andrey Andreev75546112012-07-05 11:01:29 +03001358 return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
Andrey Andreev2d486232012-07-19 14:46:51 +03001359 .$this->_compile_wh('qb_where')
1360 .$this->_compile_order_by()
Andrey Andreevc9b924c2012-07-19 13:06:02 +03001361 .($this->qb_limit ? ' LIMIT '.$this->qb_limit : '');
Andrey Andreev75546112012-07-05 11:01:29 +03001362 }
1363
1364 // --------------------------------------------------------------------
1365
1366 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001367 * Tests whether the string has an SQL operator
1368 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001369 * @param string
1370 * @return bool
1371 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001372 protected function _has_operator($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001373 {
Andrey Andreevb0478652012-07-18 15:34:46 +03001374 return (bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($str));
Derek Allard2067d1a2008-11-13 22:59:24 +00001375 }
1376
1377 // --------------------------------------------------------------------
1378
1379 /**
Andrey Andreev929fd2d2012-06-17 17:29:57 +03001380 * Returns the SQL string operator
1381 *
1382 * @param string
1383 * @return string
1384 */
1385 protected function _get_operator($str)
1386 {
Andrey Andreeve8be24b2012-07-19 16:11:17 +03001387 static $_operators;
Andrey Andreev6e704752012-07-18 00:46:33 +03001388
Andrey Andreeve8be24b2012-07-19 16:11:17 +03001389 if (empty($_operators))
Andrey Andreevb0478652012-07-18 15:34:46 +03001390 {
Andrey Andreeve8be24b2012-07-19 16:11:17 +03001391 $_les = ($this->_like_escape_str !== '')
Andrey Andreeve4742582012-10-25 13:25:13 +03001392 ? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr)), '/')
Andrey Andreeve8be24b2012-07-19 16:11:17 +03001393 : '';
Andrey Andreeve8be24b2012-07-19 16:11:17 +03001394 $_operators = array(
1395 '\s*(?:<|>|!)?=\s*', // =, <=, >=, !=
1396 '\s*<>?\s*', // <, <>
1397 '\s*>\s*', // >
1398 '\s+IS NULL', // IS NULL
1399 '\s+IS NOT NULL', // IS NOT NULL
1400 '\s+BETWEEN\s+\S+\s+AND\s+\S+', // BETWEEN value AND value
1401 '\s+IN\s*\([^\)]+\)', // IN(list)
1402 '\s+NOT IN\s*\([^\)]+\)', // NOT IN (list)
1403 '\s+LIKE\s+\S+'.$_les, // LIKE 'expr'[ ESCAPE '%s']
1404 '\s+NOT LIKE\s+\S+'.$_les // NOT LIKE 'expr'[ ESCAPE '%s']
1405 );
1406
1407 }
Andrey Andreevb0478652012-07-18 15:34:46 +03001408
Andrey Andreev6e704752012-07-18 00:46:33 +03001409 return preg_match('/'.implode('|', $_operators).'/i', $str, $match)
1410 ? $match[0] : FALSE;
Andrey Andreev929fd2d2012-06-17 17:29:57 +03001411 }
1412
1413 // --------------------------------------------------------------------
1414
1415 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001416 * Enables a native PHP function to be run, using a platform agnostic wrapper.
1417 *
Andrey Andreevae85eb42012-11-02 01:42:31 +02001418 * @param string $function Function name
Barry Mienydd671972010-10-04 16:33:58 +02001419 * @return mixed
1420 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001421 public function call_function($function)
Derek Allard2067d1a2008-11-13 22:59:24 +00001422 {
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001423 $driver = ($this->dbdriver === 'postgre') ? 'pg_' : $this->dbdriver.'_';
Barry Mienydd671972010-10-04 16:33:58 +02001424
Derek Allard2067d1a2008-11-13 22:59:24 +00001425 if (FALSE === strpos($driver, $function))
1426 {
1427 $function = $driver.$function;
1428 }
Barry Mienydd671972010-10-04 16:33:58 +02001429
Derek Allard2067d1a2008-11-13 22:59:24 +00001430 if ( ! function_exists($function))
1431 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001432 return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001433 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001434
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001435 return (func_num_args() > 1)
1436 ? call_user_func_array($function, array_splice(func_get_args(), 1))
1437 : call_user_func($function);
Derek Allard2067d1a2008-11-13 22:59:24 +00001438 }
1439
1440 // --------------------------------------------------------------------
1441
1442 /**
1443 * Set Cache Directory Path
1444 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001445 * @param string the path to the cache directory
1446 * @return void
Barry Mienydd671972010-10-04 16:33:58 +02001447 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001448 public function cache_set_path($path = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001449 {
1450 $this->cachedir = $path;
1451 }
1452
1453 // --------------------------------------------------------------------
1454
1455 /**
1456 * Enable Query Caching
1457 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001458 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001459 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001460 public function cache_on()
Derek Allard2067d1a2008-11-13 22:59:24 +00001461 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001462 return $this->cache_on = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001463 }
1464
1465 // --------------------------------------------------------------------
1466
1467 /**
1468 * Disable Query Caching
1469 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001470 * @return bool cache_on value
Barry Mienydd671972010-10-04 16:33:58 +02001471 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001472 public function cache_off()
Derek Allard2067d1a2008-11-13 22:59:24 +00001473 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001474 return $this->cache_on = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001475 }
Barry Mienydd671972010-10-04 16:33:58 +02001476
Derek Allard2067d1a2008-11-13 22:59:24 +00001477 // --------------------------------------------------------------------
1478
1479 /**
1480 * Delete the cache files associated with a particular URI
1481 *
Andrey Andreev5fd3ae82012-10-24 14:55:35 +03001482 * @param string $segment_one = ''
1483 * @param string $segment_two = ''
Andrey Andreev4c202602012-03-06 20:34:52 +02001484 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001485 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001486 public function cache_delete($segment_one = '', $segment_two = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001487 {
Andrey Andreev043f2602012-03-06 20:16:42 +02001488 return ($this->_cache_init())
1489 ? $this->CACHE->delete($segment_one, $segment_two)
1490 : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001491 }
1492
1493 // --------------------------------------------------------------------
1494
1495 /**
1496 * Delete All cache files
1497 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001498 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001499 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001500 public function cache_delete_all()
Derek Allard2067d1a2008-11-13 22:59:24 +00001501 {
Andrey Andreev043f2602012-03-06 20:16:42 +02001502 return ($this->_cache_init())
1503 ? $this->CACHE->delete_all()
1504 : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001505 }
1506
1507 // --------------------------------------------------------------------
1508
1509 /**
1510 * Initialize the Cache Class
1511 *
Andrey Andreev4c202602012-03-06 20:34:52 +02001512 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001513 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001514 protected function _cache_init()
Derek Allard2067d1a2008-11-13 22:59:24 +00001515 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001516 if (class_exists('CI_DB_Cache'))
Derek Allard2067d1a2008-11-13 22:59:24 +00001517 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001518 if (is_object($this->CACHE))
Derek Allarde37ab382009-02-03 16:13:57 +00001519 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001520 return TRUE;
Derek Allarde37ab382009-02-03 16:13:57 +00001521 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001522 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001523 elseif ( ! @include_once(BASEPATH.'database/DB_cache.php'))
1524 {
1525 return $this->cache_off();
1526 }
Derek Allarde37ab382009-02-03 16:13:57 +00001527
Derek Allard2067d1a2008-11-13 22:59:24 +00001528 $this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
1529 return TRUE;
1530 }
1531
1532 // --------------------------------------------------------------------
1533
1534 /**
1535 * Close DB Connection
1536 *
Barry Mienydd671972010-10-04 16:33:58 +02001537 * @return void
1538 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001539 public function close()
Derek Allard2067d1a2008-11-13 22:59:24 +00001540 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001541 if ($this->conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +00001542 {
Andrey Andreev79922c02012-05-23 12:27:17 +03001543 $this->_close();
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001544 $this->conn_id = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +00001545 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001546 }
Barry Mienydd671972010-10-04 16:33:58 +02001547
Derek Allard2067d1a2008-11-13 22:59:24 +00001548 // --------------------------------------------------------------------
1549
1550 /**
Andrey Andreev79922c02012-05-23 12:27:17 +03001551 * Close DB Connection
1552 *
1553 * This method would be overriden by most of the drivers.
1554 *
1555 * @return void
1556 */
1557 protected function _close()
1558 {
1559 $this->conn_id = FALSE;
1560 }
1561
1562 // --------------------------------------------------------------------
1563
1564 /**
Derek Allard2067d1a2008-11-13 22:59:24 +00001565 * Display an error message
1566 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001567 * @param string the error message
1568 * @param string any "swap" values
Andrey Andreev4c202602012-03-06 20:34:52 +02001569 * @param bool whether to localize the message
Barry Mienydd671972010-10-04 16:33:58 +02001570 * @return string sends the application/error_db.php template
1571 */
Timothy Warrene45518d2012-03-06 07:38:00 -05001572 public function display_error($error = '', $swap = '', $native = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001573 {
Derek Jonese7792202010-03-02 17:24:46 -06001574 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001575 $LANG->load('db');
1576
1577 $heading = $LANG->line('db_error_heading');
1578
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001579 if ($native === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001580 {
Andrey Andreev85a99cc2011-09-24 17:17:37 +03001581 $message = (array) $error;
Derek Allard2067d1a2008-11-13 22:59:24 +00001582 }
1583 else
1584 {
Andrey Andreev1194ad72012-10-05 17:05:46 +03001585 $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error)));
Derek Allard2067d1a2008-11-13 22:59:24 +00001586 }
Barry Mienydd671972010-10-04 16:33:58 +02001587
Pascal Kriete60f8c392010-08-25 18:03:28 +02001588 // Find the most likely culprit of the error by going through
1589 // the backtrace until the source file is no longer in the
1590 // database folder.
Pascal Kriete60f8c392010-08-25 18:03:28 +02001591 $trace = debug_backtrace();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001592 foreach ($trace as $call)
Pascal Kriete60f8c392010-08-25 18:03:28 +02001593 {
Andrey Andreev1194ad72012-10-05 17:05:46 +03001594 // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes
1595 if (DIRECTORY_SEPARATOR !== '/')
1596 {
1597 $call['file'] = str_replace('\\', '/', $call['file']);
1598 }
1599
Andrey Andreev70b78992012-10-09 10:36:04 +03001600 if (isset($call['file'], $call['class']) && strpos($call['file'], BASEPATH.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE)
Pascal Kriete60f8c392010-08-25 18:03:28 +02001601 {
1602 // Found it - use a relative path for safety
Andrey Andreev2f0dce02012-06-20 11:05:01 +03001603 $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']);
Pascal Kriete60f8c392010-08-25 18:03:28 +02001604 $message[] = 'Line Number: '.$call['line'];
Pascal Kriete60f8c392010-08-25 18:03:28 +02001605 break;
1606 }
1607 }
Barry Mienydd671972010-10-04 16:33:58 +02001608
Derek Jonese7792202010-03-02 17:24:46 -06001609 $error =& load_class('Exceptions', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +00001610 echo $error->show_error($heading, $message, 'error_db');
1611 exit;
1612 }
1613
1614 // --------------------------------------------------------------------
1615
1616 /**
1617 * Protect Identifiers
1618 *
Jamie Rumbelow7efad202012-02-19 12:37:00 +00001619 * This function is used extensively by the Query Builder class, and by
Barry Mienydd671972010-10-04 16:33:58 +02001620 * a couple functions in this class.
Derek Allard2067d1a2008-11-13 22:59:24 +00001621 * It takes a column or table name (optionally with an alias) and inserts
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001622 * the table prefix onto it. Some logic is necessary in order to deal with
Andrey Andreev4c202602012-03-06 20:34:52 +02001623 * column names that include the path. Consider a query like this:
Derek Allard2067d1a2008-11-13 22:59:24 +00001624 *
1625 * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
1626 *
1627 * Or a query with aliasing:
1628 *
1629 * SELECT m.member_id, m.member_name FROM members AS m
1630 *
1631 * Since the column name can include up to four segments (host, DB, table, column)
1632 * or also have an alias prefix, we need to do a bit of work to figure this out and
1633 * insert the table prefix (if it exists) in the proper position, and escape only
1634 * the correct identifiers.
1635 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001636 * @param string
1637 * @param bool
1638 * @param mixed
1639 * @param bool
1640 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001641 */
Andrey Andreev032e7ea2012-03-06 19:48:35 +02001642 public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001643 {
1644 if ( ! is_bool($protect_identifiers))
1645 {
Jamie Rumbelow0cd8c792012-03-08 12:52:24 +00001646 $protect_identifiers = $this->_protect_identifiers;
Derek Allard2067d1a2008-11-13 22:59:24 +00001647 }
Derek Allarde37ab382009-02-03 16:13:57 +00001648
1649 if (is_array($item))
1650 {
1651 $escaped_array = array();
Pascal Krietec3a4a8d2011-02-14 13:40:08 -05001652 foreach ($item as $k => $v)
Derek Allarde37ab382009-02-03 16:13:57 +00001653 {
Andrey Andreevbf940582012-06-10 07:05:05 +03001654 $escaped_array[$this->protect_identifiers($k)] = $this->protect_identifiers($v, $prefix_single, $protect_identifiers, $field_exists);
Derek Allarde37ab382009-02-03 16:13:57 +00001655 }
1656
1657 return $escaped_array;
1658 }
1659
Derek Allard911d3e02008-12-15 14:08:35 +00001660 // This is basically a bug fix for queries that use MAX, MIN, etc.
Barry Mienydd671972010-10-04 16:33:58 +02001661 // If a parenthesis is found we know that we do not need to
Andrey Andreev4c202602012-03-06 20:34:52 +02001662 // escape the data or add a prefix. There's probably a more graceful
Derek Allard911d3e02008-12-15 14:08:35 +00001663 // way to deal with this, but I'm not thinking of it -- Rick
1664 if (strpos($item, '(') !== FALSE)
1665 {
Andrey Andreev4db16322012-06-10 15:12:02 +03001666 return $item;
Derek Allard911d3e02008-12-15 14:08:35 +00001667 }
1668
Andrey Andreevbf940582012-06-10 07:05:05 +03001669 // Convert tabs or multiple spaces into single spaces
1670 $item = preg_replace('/\s+/', ' ', $item);
1671
Andrey Andreevbf940582012-06-10 07:05:05 +03001672 // If the item has an alias declaration we remove it and set it aside.
Andrey Andreev929fd2d2012-06-17 17:29:57 +03001673 // Note: strripos() is used in order to support spaces in table names
1674 if ($offset = strripos($item, ' AS '))
Andrey Andreevbf940582012-06-10 07:05:05 +03001675 {
Andrey Andreev929fd2d2012-06-17 17:29:57 +03001676 $alias = ($protect_identifiers)
1677 ? substr($item, $offset, 4).$this->escape_identifiers(substr($item, $offset + 4))
1678 : substr($item, $offset);
1679 $item = substr($item, 0, $offset);
1680 }
1681 elseif ($offset = strrpos($item, ' '))
1682 {
1683 $alias = ($protect_identifiers)
1684 ? ' '.$this->escape_identifiers(substr($item, $offset + 1))
1685 : substr($item, $offset);
1686 $item = substr($item, 0, $offset);
Andrey Andreevbf940582012-06-10 07:05:05 +03001687 }
1688 else
1689 {
1690 $alias = '';
1691 }
1692
Derek Allard2067d1a2008-11-13 22:59:24 +00001693 // Break the string apart if it contains periods, then insert the table prefix
1694 // in the correct location, assuming the period doesn't indicate that we're dealing
1695 // with an alias. While we're at it, we will escape the components
1696 if (strpos($item, '.') !== FALSE)
1697 {
1698 $parts = explode('.', $item);
Barry Mienydd671972010-10-04 16:33:58 +02001699
Derek Allard2067d1a2008-11-13 22:59:24 +00001700 // Does the first segment of the exploded item match
Andrey Andreev4c202602012-03-06 20:34:52 +02001701 // one of the aliases previously identified? If so,
Derek Allard2067d1a2008-11-13 22:59:24 +00001702 // we have nothing more to do other than escape the item
Jamie Rumbelow7efad202012-02-19 12:37:00 +00001703 if (in_array($parts[0], $this->qb_aliased_tables))
Derek Allard911d3e02008-12-15 14:08:35 +00001704 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001705 if ($protect_identifiers === TRUE)
1706 {
1707 foreach ($parts as $key => $val)
1708 {
1709 if ( ! in_array($val, $this->_reserved_identifiers))
1710 {
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001711 $parts[$key] = $this->escape_identifiers($val);
Derek Allard2067d1a2008-11-13 22:59:24 +00001712 }
1713 }
Barry Mienydd671972010-10-04 16:33:58 +02001714
Derek Allard2067d1a2008-11-13 22:59:24 +00001715 $item = implode('.', $parts);
Barry Mienydd671972010-10-04 16:33:58 +02001716 }
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001717
Derek Allard2067d1a2008-11-13 22:59:24 +00001718 return $item.$alias;
1719 }
Barry Mienydd671972010-10-04 16:33:58 +02001720
Andrey Andreev4c202602012-03-06 20:34:52 +02001721 // Is there a table prefix defined in the config file? If not, no need to do anything
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001722 if ($this->dbprefix !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001723 {
1724 // We now add the table prefix based on some logic.
1725 // Do we have 4 segments (hostname.database.table.column)?
1726 // If so, we add the table prefix to the column name in the 3rd segment.
1727 if (isset($parts[3]))
1728 {
1729 $i = 2;
1730 }
1731 // Do we have 3 segments (database.table.column)?
1732 // If so, we add the table prefix to the column name in 2nd position
1733 elseif (isset($parts[2]))
1734 {
1735 $i = 1;
1736 }
1737 // Do we have 2 segments (table.column)?
1738 // If so, we add the table prefix to the column name in 1st segment
1739 else
1740 {
1741 $i = 0;
1742 }
Barry Mienydd671972010-10-04 16:33:58 +02001743
Derek Allard2067d1a2008-11-13 22:59:24 +00001744 // This flag is set when the supplied $item does not contain a field name.
1745 // This can happen when this function is being called from a JOIN.
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001746 if ($field_exists === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001747 {
1748 $i++;
1749 }
Barry Mienydd671972010-10-04 16:33:58 +02001750
Derek Jones55acc8b2009-07-11 03:38:13 +00001751 // Verify table prefix and replace if necessary
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001752 if ($this->swap_pre !== '' && strpos($parts[$i], $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001753 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001754 $parts[$i] = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $parts[$i]);
Derek Jones55acc8b2009-07-11 03:38:13 +00001755 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001756 // We only add the table prefix if it does not already exist
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001757 elseif (strpos($parts[$i], $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001758 {
1759 $parts[$i] = $this->dbprefix.$parts[$i];
1760 }
Barry Mienydd671972010-10-04 16:33:58 +02001761
Derek Allard2067d1a2008-11-13 22:59:24 +00001762 // Put the parts back together
1763 $item = implode('.', $parts);
1764 }
Barry Mienydd671972010-10-04 16:33:58 +02001765
Derek Allard2067d1a2008-11-13 22:59:24 +00001766 if ($protect_identifiers === TRUE)
1767 {
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001768 $item = $this->escape_identifiers($item);
Derek Allard2067d1a2008-11-13 22:59:24 +00001769 }
Barry Mienydd671972010-10-04 16:33:58 +02001770
Derek Allard2067d1a2008-11-13 22:59:24 +00001771 return $item.$alias;
1772 }
1773
Andrey Andreev4c202602012-03-06 20:34:52 +02001774 // Is there a table prefix? If not, no need to insert it
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001775 if ($this->dbprefix !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001776 {
Derek Jones55acc8b2009-07-11 03:38:13 +00001777 // Verify table prefix and replace if necessary
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001778 if ($this->swap_pre !== '' && strpos($item, $this->swap_pre) === 0)
Derek Jones55acc8b2009-07-11 03:38:13 +00001779 {
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001780 $item = preg_replace('/^'.$this->swap_pre.'(\S+?)/', $this->dbprefix.'\\1', $item);
Derek Jones55acc8b2009-07-11 03:38:13 +00001781 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001782 // Do we prefix an item with no segments?
Alex Bilbie48a2baf2012-06-02 11:09:54 +01001783 elseif ($prefix_single === TRUE && strpos($item, $this->dbprefix) !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001784 {
1785 $item = $this->dbprefix.$item;
Barry Mienydd671972010-10-04 16:33:58 +02001786 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001787 }
1788
Andrey Andreevaf5d5582012-01-25 21:34:47 +02001789 if ($protect_identifiers === TRUE && ! in_array($item, $this->_reserved_identifiers))
Derek Allard2067d1a2008-11-13 22:59:24 +00001790 {
Andrey Andreevea09a8a2012-04-06 20:50:07 +03001791 $item = $this->escape_identifiers($item);
Derek Allard2067d1a2008-11-13 22:59:24 +00001792 }
Barry Mienydd671972010-10-04 16:33:58 +02001793
Derek Allard2067d1a2008-11-13 22:59:24 +00001794 return $item.$alias;
1795 }
Andrey Andreev4c202602012-03-06 20:34:52 +02001796
Túbal Martín511f2252011-11-24 14:43:45 +01001797 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +00001798
Túbal Martín511f2252011-11-24 14:43:45 +01001799 /**
Jamie Rumbelow17c1bed2012-03-06 21:30:38 +00001800 * Dummy method that allows Query Builder class to be disabled
Andrey Andreev16bb9bd2012-05-26 18:21:14 +03001801 * and keep count_all() working.
Túbal Martín511f2252011-11-24 14:43:45 +01001802 *
Túbal Martín511f2252011-11-24 14:43:45 +01001803 * @return void
1804 */
1805 protected function _reset_select()
1806 {
Túbal Martín511f2252011-11-24 14:43:45 +01001807 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001808
1809}
1810
Derek Allard2067d1a2008-11-13 22:59:24 +00001811/* End of file DB_driver.php */
Andrey Andreev79922c02012-05-23 12:27:17 +03001812/* Location: ./system/database/DB_driver.php */