1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author ExpressionEngine Dev Team
9
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* Database Driver Class
21
* This is the platform-independent base DB implementation class.
22
* This class will not be called directly. Rather, the adapter
23
* class for the specific database will extend and instantiate it.
25
* @package CodeIgniter
28
* @author ExpressionEngine Dev Team
29
* @link http://codeigniter.com/user_guide/database/
37
var $dbdriver = 'mysql';
39
var $char_set = 'utf8';
40
var $dbcollat = 'utf8_general_ci';
41
var $autoinit = TRUE; // Whether to automatically initialize the DB
44
var $pconnect = FALSE;
46
var $result_id = FALSE;
47
var $db_debug = FALSE;
50
var $bind_marker = '?';
51
var $save_queries = TRUE;
52
var $queries = array();
53
var $query_times = array();
54
var $data_cache = array();
55
var $trans_enabled = TRUE;
56
var $trans_strict = TRUE;
57
var $_trans_depth = 0;
58
var $_trans_status = TRUE; // Used with transactions to determine if a rollback should occur
59
var $cache_on = FALSE;
61
var $cache_autodel = FALSE;
62
var $CACHE; // The cache class object
65
var $_protect_identifiers = TRUE;
66
var $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped
68
// These are use with Oracle
76
* Constructor. Accepts one parameter containing the database
77
* connection settings.
81
function __construct($params)
83
if (is_array($params))
85
foreach ($params as $key => $val)
91
log_message('debug', 'Database Driver Class Initialized');
94
// --------------------------------------------------------------------
97
* Initialize Database Settings
99
* @access private Called by the constructor
103
function initialize()
105
// If an existing connection resource is available
106
// there is no need to connect and select the database
107
if (is_resource($this->conn_id) OR is_object($this->conn_id))
112
// ----------------------------------------------------------------
114
// Connect to the database and set the connection ID
115
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();
117
// No connection resource? Throw an error
118
if ( ! $this->conn_id)
120
log_message('error', 'Unable to connect to the database');
124
$this->display_error('db_unable_to_connect');
129
// ----------------------------------------------------------------
131
// Select the DB... assuming a database name is specified in the config file
132
if ($this->database != '')
134
if ( ! $this->db_select())
136
log_message('error', 'Unable to select database: '.$this->database);
140
$this->display_error('db_unable_to_select', $this->database);
146
// We've selected the DB. Now we set the character set
147
if ( ! $this->db_set_charset($this->char_set, $this->dbcollat))
159
// --------------------------------------------------------------------
162
* Set client character set
169
function db_set_charset($charset, $collation)
171
if ( ! $this->_db_set_charset($this->char_set, $this->dbcollat))
173
log_message('error', 'Unable to set database connection charset: '.$this->char_set);
177
$this->display_error('db_unable_to_set_charset', $this->char_set);
186
// --------------------------------------------------------------------
189
* The name of the platform in use (mysql, mssql, etc...)
196
return $this->dbdriver;
199
// --------------------------------------------------------------------
202
* Database Version Number. Returns a string containing the
203
* version of the database being used
210
if (FALSE === ($sql = $this->_version()))
214
return $this->display_error('db_unsupported_function');
219
// Some DBs have functions that return the version, and don't run special
220
// SQL queries per se. In these instances, just return the result.
221
$driver_version_exceptions = array('oci8', 'sqlite', 'cubrid');
223
if (in_array($this->dbdriver, $driver_version_exceptions))
229
$query = $this->query($sql);
230
return $query->row('ver');
234
// --------------------------------------------------------------------
239
* Accepts an SQL string as input and returns a result object upon
240
* successful execution of a "read" type query. Returns boolean TRUE
241
* upon successful execution of a "write" type query. Returns boolean
242
* FALSE upon failure, and if the $db_debug variable is set to TRUE
243
* will raise an error.
246
* @param string An SQL query string
247
* @param array An array of binding data
250
function query($sql, $binds = FALSE, $return_object = TRUE)
256
log_message('error', 'Invalid query: '.$sql);
257
return $this->display_error('db_invalid_query');
262
// Verify table prefix and replace if necessary
263
if ( ($this->dbprefix != '' AND $this->swap_pre != '') AND ($this->dbprefix != $this->swap_pre) )
265
$sql = preg_replace("/(\W)".$this->swap_pre."(\S+?)/", "\\1".$this->dbprefix."\\2", $sql);
268
// Compile binds if needed
269
if ($binds !== FALSE)
271
$sql = $this->compile_binds($sql, $binds);
274
// Is query caching enabled? If the query is a "read type"
275
// we will load the caching class and return the previously
276
// cached query if it exists
277
if ($this->cache_on == TRUE AND stristr($sql, 'SELECT'))
279
if ($this->_cache_init())
281
$this->load_rdriver();
282
if (FALSE !== ($cache = $this->CACHE->read($sql)))
289
// Save the query for debugging
290
if ($this->save_queries == TRUE)
292
$this->queries[] = $sql;
295
// Start the Query Timer
296
$time_start = list($sm, $ss) = explode(' ', microtime());
299
if (FALSE === ($this->result_id = $this->simple_query($sql)))
301
if ($this->save_queries == TRUE)
303
$this->query_times[] = 0;
306
// This will trigger a rollback if transactions are being used
307
$this->_trans_status = FALSE;
311
// grab the error number and message now, as we might run some
312
// additional queries before displaying the error
313
$error_no = $this->_error_number();
314
$error_msg = $this->_error_message();
316
// We call this function in order to roll-back queries
317
// if transactions are enabled. If we don't call this here
318
// the error message will trigger an exit, causing the
319
// transactions to remain in limbo.
320
$this->trans_complete();
322
// Log and display errors
323
log_message('error', 'Query error: '.$error_msg);
324
return $this->display_error(
326
'Error Number: '.$error_no,
336
// Stop and aggregate the query time results
337
$time_end = list($em, $es) = explode(' ', microtime());
338
$this->benchmark += ($em + $es) - ($sm + $ss);
340
if ($this->save_queries == TRUE)
342
$this->query_times[] = ($em + $es) - ($sm + $ss);
345
// Increment the query counter
346
$this->query_count++;
348
// Was the query a "write" type?
349
// If so we'll simply return true
350
if ($this->is_write_type($sql) === TRUE)
352
// If caching is enabled we'll auto-cleanup any
353
// existing files related to this particular URI
354
if ($this->cache_on == TRUE AND $this->cache_autodel == TRUE AND $this->_cache_init())
356
$this->CACHE->delete();
362
// Return TRUE if we don't need to create a result object
363
// Currently only the Oracle driver uses this when stored
364
// procedures are used
365
if ($return_object !== TRUE)
370
// Load and instantiate the result driver
372
$driver = $this->load_rdriver();
373
$RES = new $driver();
374
$RES->conn_id = $this->conn_id;
375
$RES->result_id = $this->result_id;
377
if ($this->dbdriver == 'oci8')
379
$RES->stmt_id = $this->stmt_id;
380
$RES->curs_id = NULL;
381
$RES->limit_used = $this->limit_used;
382
$this->stmt_id = FALSE;
385
// oci8 vars must be set before calling this
386
$RES->num_rows = $RES->num_rows();
388
// Is query caching enabled? If so, we'll serialize the
389
// result object and save it to a cache file.
390
if ($this->cache_on == TRUE AND $this->_cache_init())
392
// We'll create a new instance of the result object
393
// only without the platform specific driver since
394
// we can't use it with cached data (the query result
395
// resource ID won't be any good once we've cached the
396
// result object, so we'll have to compile the data
398
$CR = new CI_DB_result();
399
$CR->num_rows = $RES->num_rows();
400
$CR->result_object = $RES->result_object();
401
$CR->result_array = $RES->result_array();
403
// Reset these since cached objects can not utilize resource IDs.
405
$CR->result_id = NULL;
407
$this->CACHE->write($sql, $CR);
413
// --------------------------------------------------------------------
416
* Load the result drivers
419
* @return string the name of the result class
421
function load_rdriver()
423
$driver = 'CI_DB_'.$this->dbdriver.'_result';
425
if ( ! class_exists($driver))
427
include_once(BASEPATH.'database/DB_result.php');
428
include_once(BASEPATH.'database/drivers/'.$this->dbdriver.'/'.$this->dbdriver.'_result.php');
434
// --------------------------------------------------------------------
438
* This is a simplified version of the query() function. Internally
439
* we only use it when running transaction commands since they do
440
* not require all the features of the main query() function.
443
* @param string the sql query
446
function simple_query($sql)
448
if ( ! $this->conn_id)
453
return $this->_execute($sql);
456
// --------------------------------------------------------------------
459
* Disable Transactions
460
* This permits transactions to be disabled at run-time.
467
$this->trans_enabled = FALSE;
470
// --------------------------------------------------------------------
473
* Enable/disable Transaction Strict Mode
474
* When strict mode is enabled, if you are running multiple groups of
475
* transactions, if one group fails all groups will be rolled back.
476
* If strict mode is disabled, each group is treated autonomously, meaning
477
* a failure of one group will not affect any others
482
function trans_strict($mode = TRUE)
484
$this->trans_strict = is_bool($mode) ? $mode : TRUE;
487
// --------------------------------------------------------------------
495
function trans_start($test_mode = FALSE)
497
if ( ! $this->trans_enabled)
502
// When transactions are nested we only begin/commit/rollback the outermost ones
503
if ($this->_trans_depth > 0)
505
$this->_trans_depth += 1;
509
$this->trans_begin($test_mode);
512
// --------------------------------------------------------------------
515
* Complete Transaction
520
function trans_complete()
522
if ( ! $this->trans_enabled)
527
// When transactions are nested we only begin/commit/rollback the outermost ones
528
if ($this->_trans_depth > 1)
530
$this->_trans_depth -= 1;
534
// The query() function will set this flag to FALSE in the event that a query failed
535
if ($this->_trans_status === FALSE)
537
$this->trans_rollback();
539
// If we are NOT running in strict mode, we will reset
540
// the _trans_status flag so that subsequent groups of transactions
541
// will be permitted.
542
if ($this->trans_strict === FALSE)
544
$this->_trans_status = TRUE;
547
log_message('debug', 'DB Transaction Failure');
551
$this->trans_commit();
555
// --------------------------------------------------------------------
558
* Lets you retrieve the transaction flag to determine if it has failed
563
function trans_status()
565
return $this->_trans_status;
568
// --------------------------------------------------------------------
574
* @param string the sql statement
575
* @param array an array of bind data
578
function compile_binds($sql, $binds)
580
if (strpos($sql, $this->bind_marker) === FALSE)
585
if ( ! is_array($binds))
587
$binds = array($binds);
590
// Get the sql segments around the bind markers
591
$segments = explode($this->bind_marker, $sql);
593
// The count of bind should be 1 less then the count of segments
594
// If there are more bind arguments trim it down
595
if (count($binds) >= count($segments)) {
596
$binds = array_slice($binds, 0, count($segments)-1);
599
// Construct the binded query
600
$result = $segments[0];
602
foreach ($binds as $bind)
604
$result .= $this->escape($bind);
605
$result .= $segments[++$i];
611
// --------------------------------------------------------------------
614
* Determines if a query is a "write" type.
617
* @param string An SQL query string
620
function is_write_type($sql)
622
if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
629
// --------------------------------------------------------------------
632
* Calculate the aggregate query elapsed time
635
* @param integer The number of decimal places
638
function elapsed_time($decimals = 6)
640
return number_format($this->benchmark, $decimals);
643
// --------------------------------------------------------------------
646
* Returns the total number of queries
651
function total_queries()
653
return $this->query_count;
656
// --------------------------------------------------------------------
659
* Returns the last query that was executed
664
function last_query()
666
return end($this->queries);
669
// --------------------------------------------------------------------
672
* "Smart" Escape String
674
* Escapes data based on type
675
* Sets boolean and null types
681
function escape($str)
685
$str = "'".$this->escape_str($str)."'";
687
elseif (is_bool($str))
689
$str = ($str === FALSE) ? 0 : 1;
691
elseif (is_null($str))
699
// --------------------------------------------------------------------
704
* Calls the individual driver for platform
705
* specific escaping for LIKE conditions
711
function escape_like_str($str)
713
return $this->escape_str($str, TRUE);
716
// --------------------------------------------------------------------
721
* Retrieves the primary key. It assumes that the row in the first
722
* position is the primary key
725
* @param string the table name
728
function primary($table = '')
730
$fields = $this->list_fields($table);
732
if ( ! is_array($fields))
737
return current($fields);
740
// --------------------------------------------------------------------
743
* Returns an array of table names
748
function list_tables($constrain_by_prefix = FALSE)
750
// Is there a cached result?
751
if (isset($this->data_cache['table_names']))
753
return $this->data_cache['table_names'];
756
if (FALSE === ($sql = $this->_list_tables($constrain_by_prefix)))
760
return $this->display_error('db_unsupported_function');
766
$query = $this->query($sql);
768
if ($query->num_rows() > 0)
770
foreach ($query->result_array() as $row)
772
if (isset($row['TABLE_NAME']))
774
$retval[] = $row['TABLE_NAME'];
778
$retval[] = array_shift($row);
783
$this->data_cache['table_names'] = $retval;
784
return $this->data_cache['table_names'];
787
// --------------------------------------------------------------------
790
* Determine if a particular table exists
794
function table_exists($table_name)
796
return ( ! in_array($this->_protect_identifiers($table_name, TRUE, FALSE, FALSE), $this->list_tables())) ? FALSE : TRUE;
799
// --------------------------------------------------------------------
802
* Fetch MySQL Field Names
805
* @param string the table name
808
function list_fields($table = '')
810
// Is there a cached result?
811
if (isset($this->data_cache['field_names'][$table]))
813
return $this->data_cache['field_names'][$table];
820
return $this->display_error('db_field_param_missing');
825
if (FALSE === ($sql = $this->_list_columns($table)))
829
return $this->display_error('db_unsupported_function');
834
$query = $this->query($sql);
837
foreach ($query->result_array() as $row)
839
if (isset($row['COLUMN_NAME']))
841
$retval[] = $row['COLUMN_NAME'];
845
$retval[] = current($row);
849
$this->data_cache['field_names'][$table] = $retval;
850
return $this->data_cache['field_names'][$table];
853
// --------------------------------------------------------------------
856
* Determine if a particular field exists
862
function field_exists($field_name, $table_name)
864
return ( ! in_array($field_name, $this->list_fields($table_name))) ? FALSE : TRUE;
867
// --------------------------------------------------------------------
870
* Returns an object with field data
873
* @param string the table name
876
function field_data($table = '')
882
return $this->display_error('db_field_param_missing');
887
$query = $this->query($this->_field_data($this->_protect_identifiers($table, TRUE, NULL, FALSE)));
889
return $query->field_data();
892
// --------------------------------------------------------------------
895
* Generate an insert string
898
* @param string the table upon which the query will be performed
899
* @param array an associative array data of key/values
902
function insert_string($table, $data)
907
foreach ($data as $key => $val)
909
$fields[] = $this->_escape_identifiers($key);
910
$values[] = $this->escape($val);
913
return $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $values);
916
// --------------------------------------------------------------------
919
* Generate an update string
922
* @param string the table upon which the query will be performed
923
* @param array an associative array data of key/values
924
* @param mixed the "where" statement
927
function update_string($table, $data, $where)
935
foreach ($data as $key => $val)
937
$fields[$this->_protect_identifiers($key)] = $this->escape($val);
940
if ( ! is_array($where))
942
$dest = array($where);
947
foreach ($where as $key => $val)
949
$prefix = (count($dest) == 0) ? '' : ' AND ';
953
if ( ! $this->_has_operator($key))
958
$val = ' '.$this->escape($val);
961
$dest[] = $prefix.$key.$val;
965
return $this->_update($this->_protect_identifiers($table, TRUE, NULL, FALSE), $fields, $dest);
968
// --------------------------------------------------------------------
971
* Tests whether the string has an SQL operator
977
function _has_operator($str)
980
if ( ! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
988
// --------------------------------------------------------------------
991
* Enables a native PHP function to be run, using a platform agnostic wrapper.
994
* @param string the function name
995
* @param mixed any parameters needed by the function
998
function call_function($function)
1000
$driver = ($this->dbdriver == 'postgre') ? 'pg_' : $this->dbdriver.'_';
1002
if (FALSE === strpos($driver, $function))
1004
$function = $driver.$function;
1007
if ( ! function_exists($function))
1009
if ($this->db_debug)
1011
return $this->display_error('db_unsupported_function');
1017
$args = (func_num_args() > 1) ? array_splice(func_get_args(), 1) : null;
1020
return call_user_func($function);
1024
return call_user_func_array($function, $args);
1029
// --------------------------------------------------------------------
1032
* Set Cache Directory Path
1035
* @param string the path to the cache directory
1038
function cache_set_path($path = '')
1040
$this->cachedir = $path;
1043
// --------------------------------------------------------------------
1046
* Enable Query Caching
1053
$this->cache_on = TRUE;
1057
// --------------------------------------------------------------------
1060
* Disable Query Caching
1065
function cache_off()
1067
$this->cache_on = FALSE;
1072
// --------------------------------------------------------------------
1075
* Delete the cache files associated with a particular URI
1080
function cache_delete($segment_one = '', $segment_two = '')
1082
if ( ! $this->_cache_init())
1086
return $this->CACHE->delete($segment_one, $segment_two);
1089
// --------------------------------------------------------------------
1092
* Delete All cache files
1097
function cache_delete_all()
1099
if ( ! $this->_cache_init())
1104
return $this->CACHE->delete_all();
1107
// --------------------------------------------------------------------
1110
* Initialize the Cache Class
1115
function _cache_init()
1117
if (is_object($this->CACHE) AND class_exists('CI_DB_Cache'))
1122
if ( ! class_exists('CI_DB_Cache'))
1124
if ( ! @include(BASEPATH.'database/DB_cache.php'))
1126
return $this->cache_off();
1130
$this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects
1134
// --------------------------------------------------------------------
1137
* Close DB Connection
1144
if (is_resource($this->conn_id) OR is_object($this->conn_id))
1146
$this->_close($this->conn_id);
1148
$this->conn_id = FALSE;
1151
// --------------------------------------------------------------------
1154
* Display an error message
1157
* @param string the error message
1158
* @param string any "swap" values
1159
* @param boolean whether to localize the message
1160
* @return string sends the application/error_db.php template
1162
function display_error($error = '', $swap = '', $native = FALSE)
1164
$LANG =& load_class('Lang', 'core');
1167
$heading = $LANG->line('db_error_heading');
1169
if ($native == TRUE)
1175
$message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
1178
// Find the most likely culprit of the error by going through
1179
// the backtrace until the source file is no longer in the
1182
$trace = debug_backtrace();
1184
foreach ($trace as $call)
1186
if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE)
1188
// Found it - use a relative path for safety
1189
$message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']);
1190
$message[] = 'Line Number: '.$call['line'];
1196
$error =& load_class('Exceptions', 'core');
1197
echo $error->show_error($heading, $message, 'error_db');
1201
// --------------------------------------------------------------------
1204
* Protect Identifiers
1206
* This function adds backticks if appropriate based on db type
1209
* @param mixed the item to escape
1210
* @return mixed the item with backticks
1212
function protect_identifiers($item, $prefix_single = FALSE)
1214
return $this->_protect_identifiers($item, $prefix_single);
1217
// --------------------------------------------------------------------
1220
* Protect Identifiers
1222
* This function is used extensively by the Active Record class, and by
1223
* a couple functions in this class.
1224
* It takes a column or table name (optionally with an alias) and inserts
1225
* the table prefix onto it. Some logic is necessary in order to deal with
1226
* column names that include the path. Consider a query like this:
1228
* SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
1230
* Or a query with aliasing:
1232
* SELECT m.member_id, m.member_name FROM members AS m
1234
* Since the column name can include up to four segments (host, DB, table, column)
1235
* or also have an alias prefix, we need to do a bit of work to figure this out and
1236
* insert the table prefix (if it exists) in the proper position, and escape only
1237
* the correct identifiers.
1246
function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
1248
if ( ! is_bool($protect_identifiers))
1250
$protect_identifiers = $this->_protect_identifiers;
1253
if (is_array($item))
1255
$escaped_array = array();
1257
foreach ($item as $k => $v)
1259
$escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v);
1262
return $escaped_array;
1265
// Convert tabs or multiple spaces into single spaces
1266
$item = preg_replace('/[\t ]+/', ' ', $item);
1268
// If the item has an alias declaration we remove it and set it aside.
1269
// Basically we remove everything to the right of the first space
1270
if (strpos($item, ' ') !== FALSE)
1272
$alias = strstr($item, ' ');
1273
$item = substr($item, 0, - strlen($alias));
1280
// This is basically a bug fix for queries that use MAX, MIN, etc.
1281
// If a parenthesis is found we know that we do not need to
1282
// escape the data or add a prefix. There's probably a more graceful
1283
// way to deal with this, but I'm not thinking of it -- Rick
1284
if (strpos($item, '(') !== FALSE)
1286
return $item.$alias;
1289
// Break the string apart if it contains periods, then insert the table prefix
1290
// in the correct location, assuming the period doesn't indicate that we're dealing
1291
// with an alias. While we're at it, we will escape the components
1292
if (strpos($item, '.') !== FALSE)
1294
$parts = explode('.', $item);
1296
// Does the first segment of the exploded item match
1297
// one of the aliases previously identified? If so,
1298
// we have nothing more to do other than escape the item
1299
if (in_array($parts[0], $this->ar_aliased_tables))
1301
if ($protect_identifiers === TRUE)
1303
foreach ($parts as $key => $val)
1305
if ( ! in_array($val, $this->_reserved_identifiers))
1307
$parts[$key] = $this->_escape_identifiers($val);
1311
$item = implode('.', $parts);
1313
return $item.$alias;
1316
// Is there a table prefix defined in the config file? If not, no need to do anything
1317
if ($this->dbprefix != '')
1319
// We now add the table prefix based on some logic.
1320
// Do we have 4 segments (hostname.database.table.column)?
1321
// If so, we add the table prefix to the column name in the 3rd segment.
1322
if (isset($parts[3]))
1326
// Do we have 3 segments (database.table.column)?
1327
// If so, we add the table prefix to the column name in 2nd position
1328
elseif (isset($parts[2]))
1332
// Do we have 2 segments (table.column)?
1333
// If so, we add the table prefix to the column name in 1st segment
1339
// This flag is set when the supplied $item does not contain a field name.
1340
// This can happen when this function is being called from a JOIN.
1341
if ($field_exists == FALSE)
1346
// Verify table prefix and replace if necessary
1347
if ($this->swap_pre != '' && strncmp($parts[$i], $this->swap_pre, strlen($this->swap_pre)) === 0)
1349
$parts[$i] = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $parts[$i]);
1352
// We only add the table prefix if it does not already exist
1353
if (substr($parts[$i], 0, strlen($this->dbprefix)) != $this->dbprefix)
1355
$parts[$i] = $this->dbprefix.$parts[$i];
1358
// Put the parts back together
1359
$item = implode('.', $parts);
1362
if ($protect_identifiers === TRUE)
1364
$item = $this->_escape_identifiers($item);
1367
return $item.$alias;
1370
// Is there a table prefix? If not, no need to insert it
1371
if ($this->dbprefix != '')
1373
// Verify table prefix and replace if necessary
1374
if ($this->swap_pre != '' && strncmp($item, $this->swap_pre, strlen($this->swap_pre)) === 0)
1376
$item = preg_replace("/^".$this->swap_pre."(\S+?)/", $this->dbprefix."\\1", $item);
1379
// Do we prefix an item with no segments?
1380
if ($prefix_single == TRUE AND substr($item, 0, strlen($this->dbprefix)) != $this->dbprefix)
1382
$item = $this->dbprefix.$item;
1386
if ($protect_identifiers === TRUE AND ! in_array($item, $this->_reserved_identifiers))
1388
$item = $this->_escape_identifiers($item);
1391
return $item.$alias;
1394
// --------------------------------------------------------------------
1397
* Dummy method that allows Active Record class to be disabled
1399
* This function is used extensively by every db driver.
1403
protected function _reset_select()
1409
/* End of file DB_driver.php */
1410
/* Location: ./system/database/DB_driver.php */
b'\\ No newline at end of file'