-
Notifications
You must be signed in to change notification settings - Fork 0
CI_DB_driver
Database Driver Class
This is the platform-independent base DB implementation class. This class will not be called directly. Rather, the adapter class for the specific database will extend and instantiate it.
- Class name: CI_DB_driver
- Namespace:
- This is an abstract class
public string $dsn
Data Source Name / Connect string
- Visibility: public
public string $username
Username
- Visibility: public
public string $password
Password
- Visibility: public
public string $hostname
Hostname
- Visibility: public
public string $database
Database name
- Visibility: public
public string $dbdriver = 'mysqli'
Database driver
- Visibility: public
public string $subdriver
Sub-driver
- Visibility: public
public string $dbprefix = ''
Table prefix
- Visibility: public
public string $char_set = 'utf8'
Character set
- Visibility: public
public string $dbcollat = 'utf8_general_ci'
Collation
- Visibility: public
public mixed $encrypt = FALSE
Encryption flag/data
- Visibility: public
public string $swap_pre = ''
Swap Prefix
- Visibility: public
public integer $port = ''
Database port
- Visibility: public
public boolean $pconnect = FALSE
Persistent connection flag
- Visibility: public
public object $conn_id = FALSE
Connection ID
- Visibility: public
public object $result_id = FALSE
Result ID
- Visibility: public
public boolean $db_debug = FALSE
Debug flag
Whether to display error messages.
- Visibility: public
public integer $benchmark
Benchmark time
- Visibility: public
public integer $query_count
Executed queries count
- Visibility: public
public string $bind_marker = '?'
Bind marker
Character used to identify values in a prepared statement.
- Visibility: public
public boolean $save_queries = TRUE
Save queries flag
Whether to keep an in-memory history of queries for debugging purposes.
- Visibility: public
public array<mixed,string> $queries = array()
Queries list
- Visibility: public
public array $query_times = array()
Query times
A list of times that queries took to execute.
- Visibility: public
public array $data_cache = array()
Data cache
An internal generic value cache.
- Visibility: public
public boolean $trans_enabled = TRUE
Transaction enabled flag
- Visibility: public
public boolean $trans_strict = TRUE
Strict transaction mode flag
- Visibility: public
protected integer $_trans_depth
Transaction depth level
- Visibility: protected
protected boolean $_trans_status = TRUE
Transaction status flag
Used with transactions to determine if a rollback should occur.
- Visibility: protected
protected boolean $_trans_failure = FALSE
Transaction failure flag
Used with transactions to determine if a transaction has failed.
- Visibility: protected
public boolean $cache_on = FALSE
Cache On flag
- Visibility: public
public boolean $cachedir = ''
Cache directory path
- Visibility: public
public boolean $cache_autodel = FALSE
Cache auto-delete flag
- Visibility: public
public object $CACHE
DB Cache object
- Visibility: public
protected boolean $_protect_identifiers = TRUE
Protect identifiers flag
- Visibility: protected
protected array<mixed,string> $_reserved_identifiers = array('*')
List of reserved identifiers
Identifiers that must NOT be escaped.
- Visibility: protected
protected string $_escape_char = '"'
Identifier escape character
- Visibility: protected
protected string $_like_escape_str = " ESCAPE '%s' "
ESCAPE statement string
- Visibility: protected
protected string $_like_escape_chr = '!'
ESCAPE character
- Visibility: protected
protected array $_random_keyword = array('RAND()', 'RAND(%d)')
ORDER BY random keyword
- Visibility: protected
protected string $_count_string = 'SELECT COUNT(*) AS '
COUNT string
- Visibility: protected
void CI_DB_driver::__construct(array $params)
Class constructor
- Visibility: public
- $params array
boolean CI_DB_driver::initialize()
Initialize Database Settings
- Visibility: public
mixed CI_DB_driver::db_connect()
DB connect
This is just a dummy method that all drivers will override.
- Visibility: public
mixed CI_DB_driver::db_pconnect()
Persistent database connection
- Visibility: public
void CI_DB_driver::reconnect()
Reconnect
Keep / reestablish the db connection if no queries have been sent for a length of time exceeding the server's idle timeout.
This is just a dummy method to allow drivers without such functionality to not declare it, while others will override it.
- Visibility: public
boolean CI_DB_driver::db_select()
Select database
This is just a dummy method to allow drivers without such functionality to not declare it, while others will override it.
- Visibility: public
boolean CI_DB_driver::db_set_charset($charset)
Set client character set
- Visibility: public
- $charset mixed
string CI_DB_driver::platform()
The name of the platform in use (mysql, mssql, etc.
..)
- Visibility: public
string CI_DB_driver::version()
Database version number
Returns a string containing the version of the database being used. Most drivers will override this method.
- Visibility: public
string CI_DB_driver::_version()
Version number query string
- Visibility: protected
mixed CI_DB_driver::query(string $sql, array $binds, boolean $return_object)
Execute the query
Accepts an SQL string as input and returns a result object upon successful execution of a "read" type query. Returns boolean TRUE upon successful execution of a "write" type query. Returns boolean FALSE upon failure, and if the $db_debug variable is set to TRUE will raise an error.
- Visibility: public
- $sql string
- $binds array - <p>= FALSE An array of binding data</p>
- $return_object boolean - <p>= NULL</p>
string CI_DB_driver::load_rdriver()
Load the result drivers
- Visibility: public
mixed CI_DB_driver::simple_query($sql)
Simple Query This is a simplified version of the query() function. Internally we only use it when running transaction commands since they do not require all the features of the main query() function.
- Visibility: public
- $sql mixed
void CI_DB_driver::trans_off()
Disable Transactions This permits transactions to be disabled at run-time.
- Visibility: public
void CI_DB_driver::trans_strict(boolean $mode)
Enable/disable Transaction Strict Mode When strict mode is enabled, if you are running multiple groups of transactions, if one group fails all groups will be rolled back.
If strict mode is disabled, each group is treated autonomously, meaning a failure of one group will not affect any others
- Visibility: public
- $mode boolean - <p>= TRUE</p>
void CI_DB_driver::trans_start(boolean $test_mode)
Start Transaction
- Visibility: public
- $test_mode boolean - <p>= FALSE</p>
boolean CI_DB_driver::trans_complete()
Complete Transaction
- Visibility: public
boolean CI_DB_driver::trans_status()
Lets you retrieve the transaction flag to determine if it has failed
- Visibility: public
string CI_DB_driver::compile_binds($sql, $binds)
Compile Bindings
- Visibility: public
- $sql mixed
- $binds mixed
boolean CI_DB_driver::is_write_type($sql)
Determines if a query is a "write" type.
- Visibility: public
- $sql mixed
string CI_DB_driver::elapsed_time($decimals)
Calculate the aggregate query elapsed time
- Visibility: public
- $decimals mixed
integer CI_DB_driver::total_queries()
Returns the total number of queries
- Visibility: public
string CI_DB_driver::last_query()
Returns the last query that was executed
- Visibility: public
mixed CI_DB_driver::escape($str)
"Smart" Escape String
Escapes data based on type Sets boolean and null types
- Visibility: public
- $str mixed
string CI_DB_driver::escape_str(string|array<mixed,string> $str, boolean $like)
Escape String
- Visibility: public
- $str string|array<mixed,string> - <p>Input string</p>
- $like boolean - <p>Whether or not the string will be used in a LIKE condition</p>
mixed CI_DB_driver::escape_like_str($str)
Escape LIKE String
Calls the individual driver for platform specific escaping for LIKE conditions
- Visibility: public
- $str mixed
string CI_DB_driver::_escape_str($str)
Platform-dependant string escape
- Visibility: protected
- $str mixed
string CI_DB_driver::primary(string $table)
Primary
Retrieves the primary key. It assumes that the row in the first position is the primary key
- Visibility: public
- $table string - <p>Table name</p>
integer CI_DB_driver::count_all($table)
"Count All" query
Generates a platform-specific query string that counts all records in the specified database
- Visibility: public
- $table mixed
array CI_DB_driver::list_tables(string $constrain_by_prefix)
Returns an array of table names
- Visibility: public
- $constrain_by_prefix string - <p>= FALSE</p>
boolean CI_DB_driver::table_exists(string $table_name)
Determine if a particular table exists
- Visibility: public
- $table_name string
array CI_DB_driver::list_fields(string $table)
Fetch Field Names
- Visibility: public
- $table string - <p>Table name</p>
boolean CI_DB_driver::field_exists($field_name, $table_name)
Determine if a particular field exists
- Visibility: public
- $field_name mixed
- $table_name mixed
array CI_DB_driver::field_data(string $table)
Returns an object with field data
- Visibility: public
- $table string - <p>the table name</p>
mixed CI_DB_driver::escape_identifiers($item)
Escape the SQL Identifiers
This function escapes column and table names
- Visibility: public
- $item mixed
string CI_DB_driver::insert_string($table, $data)
Generate an insert string
- Visibility: public
- $table mixed
- $data mixed
string CI_DB_driver::_insert($table, $keys, $values)
Insert statement
Generates a platform-specific insert string from the supplied data
- Visibility: protected
- $table mixed
- $keys mixed
- $values mixed
string CI_DB_driver::update_string($table, $data, $where)
Generate an update string
- Visibility: public
- $table mixed
- $data mixed
- $where mixed
string CI_DB_driver::_update($table, $values)
Update statement
Generates a platform-specific update string from the supplied data
- Visibility: protected
- $table mixed
- $values mixed
boolean CI_DB_driver::_has_operator($str)
Tests whether the string has an SQL operator
- Visibility: protected
- $str mixed
string CI_DB_driver::_get_operator($str)
Returns the SQL string operator
- Visibility: protected
- $str mixed
mixed CI_DB_driver::call_function(string $function)
Enables a native PHP function to be run, using a platform agnostic wrapper.
- Visibility: public
- $function string - <p>Function name</p>
void CI_DB_driver::cache_set_path($path)
Set Cache Directory Path
- Visibility: public
- $path mixed
boolean CI_DB_driver::cache_on()
Enable Query Caching
- Visibility: public
boolean CI_DB_driver::cache_off()
Disable Query Caching
- Visibility: public
boolean CI_DB_driver::cache_delete(string $segment_one, string $segment_two)
Delete the cache files associated with a particular URI
- Visibility: public
- $segment_one string - <p>= ''</p>
- $segment_two string - <p>= ''</p>
boolean CI_DB_driver::cache_delete_all()
Delete All cache files
- Visibility: public
boolean CI_DB_driver::_cache_init()
Initialize the Cache Class
- Visibility: protected
void CI_DB_driver::close()
Close DB Connection
- Visibility: public
void CI_DB_driver::_close()
Close DB Connection
This method would be overridden by most of the drivers.
- Visibility: protected
string CI_DB_driver::display_error($error, $swap, $native)
Display an error message
- Visibility: public
- $error mixed
- $swap mixed
- $native mixed
string CI_DB_driver::protect_identifiers($item, $prefix_single, $protect_identifiers, $field_exists)
Protect Identifiers
This function is used extensively by the Query Builder class, and by a couple functions in this class. It takes a column or table name (optionally with an alias) and inserts the table prefix onto it. Some logic is necessary in order to deal with column names that include the path. Consider a query like this:
SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
Or a query with aliasing:
SELECT m.member_id, m.member_name FROM members AS m
Since the column name can include up to four segments (host, DB, table, column) or also have an alias prefix, we need to do a bit of work to figure this out and insert the table prefix (if it exists) in the proper position, and escape only the correct identifiers.
- Visibility: public
- $item mixed
- $prefix_single mixed
- $protect_identifiers mixed
- $field_exists mixed
void CI_DB_driver::_reset_select()
Dummy method that allows Query Builder class to be disabled and keep count_all() working.
- Visibility: protected