PHP Class CI_DB_driver, TastyIgniter

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.
Author: ExpressionEngine Dev Team
Show file Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$CACHE object DB Cache object
$benchmark integer Benchmark time
$bind_marker string Character used to identify values in a prepared statement.
$cache_autodel boolean Cache auto-delete flag
$cache_on boolean Cache On flag
$cachedir boolean Cache directory path
$char_set string Character set
$conn_id object | resource Connection ID
$data_cache array An internal generic value cache.
$database string Database name
$db_debug boolean Whether to display error messages.
$dbcollat string Collation
$dbdriver string Database driver
$dbprefix string Table prefix
$dsn string Data Source Name / Connect string
$encrypt mixed Encryption flag/data
$hostname string Hostname
$password string Password
$pconnect boolean Persistent connection flag
$port integer Database port
$queries string[] Queries list
$query_count integer Executed queries count
$query_times array A list of times that queries took to execute.
$result_id object | resource Result ID
$save_queries boolean Whether to keep an in-memory history of queries for debugging purposes.
$subdriver string Sub-driver
$swap_pre string Swap Prefix
$trans_enabled boolean Transaction enabled flag
$trans_strict boolean Strict transaction mode flag
$username string Username

Protected Properties

Property Type Description
$_count_string string COUNT string
$_escape_char string Identifier escape character
$_like_escape_chr string ESCAPE character
$_like_escape_str string ESCAPE statement string
$_protect_identifiers boolean Protect identifiers flag
$_random_keyword array ORDER BY random keyword
$_reserved_identifiers string[] Identifiers that must NOT be escaped.
$_trans_depth integer Transaction depth level
$_trans_failure boolean Used with transactions to determine if a transaction has failed.
$_trans_status boolean Used with transactions to determine if a rollback should occur.

Public Methods

Method Description
__construct ( array $params ) : void Class constructor
cache_delete ( string $segment_one = '', string $segment_two = '' ) : boolean Delete the cache files associated with a particular URI
cache_delete_all ( ) : boolean Delete All cache files
cache_off ( ) : boolean Disable Query Caching
cache_on ( ) : boolean Enable Query Caching
cache_set_path ( $path = '' ) : void Set Cache Directory Path
call_function ( string $function ) : mixed Enables a native PHP function to be run, using a platform agnostic wrapper.
close ( ) : void Close DB Connection
compile_binds ( $sql, $binds ) : string Compile Bindings
count_all ( $table = '' ) : integer "Count All" query
db_connect ( ) : mixed DB connect
db_pconnect ( ) : mixed Persistent database connection
db_select ( ) : boolean Select database
db_set_charset ( $charset ) : boolean Set client character set
display_error ( $error = '', $swap = '', $native = FALSE ) : string Display an error message
elapsed_time ( $decimals = 6 ) : string Calculate the aggregate query elapsed time
error ( ) : array Last error
escape ( $str ) : mixed "Smart" Escape String
escape_identifiers ( $item ) : mixed Escape the SQL Identifiers
escape_like_str ( $str ) : mixed Escape LIKE String
escape_str ( string | string[] $str, boolean $like = FALSE ) : string Escape String
field_data ( string $table ) : array Returns an object with field data
field_exists ( $field_name, $table_name ) : boolean Determine if a particular field exists
initialize ( ) : boolean Initialize Database Settings
insert_string ( $table, $data ) : string Generate an insert string
is_write_type ( $sql ) : boolean Determines if a query is a "write" type.
last_query ( ) : string Returns the last query that was executed
list_fields ( string $table ) : array Fetch Field Names
list_tables ( string $constrain_by_prefix = FALSE ) : array Returns an array of table names
load_rdriver ( ) : string Load the result drivers
platform ( ) : string The name of the platform in use (mysql, mssql, etc.
primary ( string $table ) : string Primary
protect_identifiers ( $item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE ) : string Protect Identifiers
query ( string $sql, array $binds = FALSE, boolean $return_object = NULL ) : mixed Execute the query
reconnect ( ) : void Reconnect
simple_query ( $sql ) : mixed 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.
table_exists ( string $table_name ) : boolean Determine if a particular table exists
total_queries ( ) : integer Returns the total number of queries
trans_begin ( boolean $test_mode = FALSE ) : boolean Begin Transaction
trans_commit ( ) : boolean Commit Transaction
trans_complete ( ) : boolean Complete Transaction
trans_off ( ) : void Disable Transactions This permits transactions to be disabled at run-time.
trans_rollback ( ) : boolean Rollback Transaction
trans_start ( boolean $test_mode = FALSE ) : boolean Start Transaction
trans_status ( ) : boolean Lets you retrieve the transaction flag to determine if it has failed
trans_strict ( boolean $mode = TRUE ) : void Enable/disable Transaction Strict Mode
update_string ( $table, $data, $where ) : string Generate an update string
version ( ) : string Database version number

Protected Methods

Method Description
_cache_init ( ) : boolean Initialize the Cache Class
_close ( ) : void Close DB Connection
_escape_str ( $str ) : string Platform-dependant string escape
_get_operator ( $str ) : string Returns the SQL string operator
_has_operator ( $str ) : boolean Tests whether the string has an SQL operator
_insert ( $table, $keys, $values ) : string Insert statement
_reset_select ( ) : void Dummy method that allows Query Builder class to be disabled and keep count_all() working.
_update ( $table, $values ) : string Update statement
_version ( ) : string Version number query string

Method Details

__construct() public method

Class constructor
public __construct ( array $params ) : void
$params array
return void

_cache_init() protected method

Initialize the Cache Class
protected _cache_init ( ) : boolean
return boolean

_close() protected method

This method would be overridden by most of the drivers.
protected _close ( ) : void
return void

_escape_str() protected method

Platform-dependant string escape
protected _escape_str ( $str ) : string
return string

_get_operator() protected method

Returns the SQL string operator
protected _get_operator ( $str ) : string
return string

_has_operator() protected method

Tests whether the string has an SQL operator
protected _has_operator ( $str ) : boolean
return boolean

_insert() protected method

Generates a platform-specific insert string from the supplied data
protected _insert ( $table, $keys, $values ) : string
return string

_reset_select() protected method

Dummy method that allows Query Builder class to be disabled and keep count_all() working.
protected _reset_select ( ) : void
return void

_update() protected method

Generates a platform-specific update string from the supplied data
protected _update ( $table, $values ) : string
return string

_version() protected method

Version number query string
protected _version ( ) : string
return string

cache_delete() public method

Delete the cache files associated with a particular URI
public cache_delete ( string $segment_one = '', string $segment_two = '' ) : boolean
$segment_one string = ''
$segment_two string = ''
return boolean

cache_delete_all() public method

Delete All cache files
public cache_delete_all ( ) : boolean
return boolean

cache_off() public method

Disable Query Caching
public cache_off ( ) : boolean
return boolean cache_on value

cache_on() public method

Enable Query Caching
public cache_on ( ) : boolean
return boolean cache_on value

cache_set_path() public method

Set Cache Directory Path
public cache_set_path ( $path = '' ) : void
return void

call_function() public method

Enables a native PHP function to be run, using a platform agnostic wrapper.
public call_function ( string $function ) : mixed
$function string Function name
return mixed

close() public method

Close DB Connection
public close ( ) : void
return void

compile_binds() public method

Compile Bindings
public compile_binds ( $sql, $binds ) : string
return string

count_all() public method

Generates a platform-specific query string that counts all records in the specified database
public count_all ( $table = '' ) : integer
return integer

db_connect() public method

This is just a dummy method that all drivers will override.
public db_connect ( ) : mixed
return mixed

db_pconnect() public method

Persistent database connection
public db_pconnect ( ) : mixed
return mixed

db_select() public method

This is just a dummy method to allow drivers without such functionality to not declare it, while others will override it.
public db_select ( ) : boolean
return boolean

db_set_charset() public method

Set client character set
public db_set_charset ( $charset ) : boolean
return boolean

display_error() public method

Display an error message
public display_error ( $error = '', $swap = '', $native = FALSE ) : string
return string sends the application/views/errors/error_db.php template

elapsed_time() public method

Calculate the aggregate query elapsed time
public elapsed_time ( $decimals = 6 ) : string
return string

error() public method

Last error
public error ( ) : array
return array

escape() public method

Escapes data based on type Sets boolean and null types
public escape ( $str ) : mixed
return mixed

escape_identifiers() public method

This function escapes column and table names
public escape_identifiers ( $item ) : mixed
return mixed

escape_like_str() public method

Calls the individual driver for platform specific escaping for LIKE conditions
public escape_like_str ( $str ) : mixed
return mixed

escape_str() public method

Escape String
public escape_str ( string | string[] $str, boolean $like = FALSE ) : string
$str string | string[] Input string
$like boolean Whether or not the string will be used in a LIKE condition
return string

field_data() public method

Returns an object with field data
public field_data ( string $table ) : array
$table string the table name
return array

field_exists() public method

Determine if a particular field exists
public field_exists ( $field_name, $table_name ) : boolean
return boolean

initialize() public method

Initialize Database Settings
public initialize ( ) : boolean
return boolean

insert_string() public method

Generate an insert string
public insert_string ( $table, $data ) : string
return string

is_write_type() public method

Determines if a query is a "write" type.
public is_write_type ( $sql ) : boolean
return boolean

last_query() public method

Returns the last query that was executed
public last_query ( ) : string
return string

list_fields() public method

Fetch Field Names
public list_fields ( string $table ) : array
$table string Table name
return array

list_tables() public method

Returns an array of table names
public list_tables ( string $constrain_by_prefix = FALSE ) : array
$constrain_by_prefix string = FALSE
return array

load_rdriver() public method

Load the result drivers
public load_rdriver ( ) : string
return string the name of the result class

platform() public method

..)
public platform ( ) : string
return string

primary() public method

Retrieves the primary key. It assumes that the row in the first position is the primary key
public primary ( string $table ) : string
$table string Table name
return string

protect_identifiers() public method

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 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.
public protect_identifiers ( $item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE ) : string
return string

query() public method

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.
public query ( string $sql, array $binds = FALSE, boolean $return_object = NULL ) : mixed
$sql string
$binds array = FALSE An array of binding data
$return_object boolean = NULL
return mixed

reconnect() public method

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.
public reconnect ( ) : void
return void

simple_query() public method

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.
public simple_query ( $sql ) : mixed
return mixed

table_exists() public method

Determine if a particular table exists
public table_exists ( string $table_name ) : boolean
$table_name string
return boolean

total_queries() public method

Returns the total number of queries
public total_queries ( ) : integer
return integer

trans_begin() public method

Begin Transaction
public trans_begin ( boolean $test_mode = FALSE ) : boolean
$test_mode boolean
return boolean

trans_commit() public method

Commit Transaction
public trans_commit ( ) : boolean
return boolean

trans_complete() public method

Complete Transaction
public trans_complete ( ) : boolean
return boolean

trans_off() public method

Disable Transactions This permits transactions to be disabled at run-time.
public trans_off ( ) : void
return void

trans_rollback() public method

Rollback Transaction
public trans_rollback ( ) : boolean
return boolean

trans_start() public method

Start Transaction
public trans_start ( boolean $test_mode = FALSE ) : boolean
$test_mode boolean = FALSE
return boolean

trans_status() public method

Lets you retrieve the transaction flag to determine if it has failed
public trans_status ( ) : boolean
return boolean

trans_strict() public method

When strict mode is enabled, if you are running multiple groups of transactions, if one group fails all subsequent 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
public trans_strict ( boolean $mode = TRUE ) : void
$mode boolean = TRUE
return void

update_string() public method

Generate an update string
public update_string ( $table, $data, $where ) : string
return string

version() public method

Returns a string containing the version of the database being used. Most drivers will override this method.
public version ( ) : string
return string

Property Details

$CACHE public property

DB Cache object
See also: CI_DB_cache
public object $CACHE
return object

$_count_string protected property

COUNT string
protected string $_count_string
return string

$_escape_char protected property

Identifier escape character
protected string $_escape_char
return string

$_like_escape_chr protected property

ESCAPE character
protected string $_like_escape_chr
return string

$_like_escape_str protected property

ESCAPE statement string
protected string $_like_escape_str
return string

$_protect_identifiers protected property

Protect identifiers flag
protected bool $_protect_identifiers
return boolean

$_random_keyword protected property

ORDER BY random keyword
protected array $_random_keyword
return array

$_reserved_identifiers protected property

Identifiers that must NOT be escaped.
protected string[] $_reserved_identifiers
return string[]

$_trans_depth protected property

Transaction depth level
protected int $_trans_depth
return integer

$_trans_failure protected property

Used with transactions to determine if a transaction has failed.
protected bool $_trans_failure
return boolean

$_trans_status protected property

Used with transactions to determine if a rollback should occur.
protected bool $_trans_status
return boolean

$benchmark public property

Benchmark time
public int $benchmark
return integer

$bind_marker public property

Character used to identify values in a prepared statement.
public string $bind_marker
return string

$cache_autodel public property

Cache auto-delete flag
public bool $cache_autodel
return boolean

$cache_on public property

Cache On flag
public bool $cache_on
return boolean

$cachedir public property

Cache directory path
public bool $cachedir
return boolean

$char_set public property

Character set
public string $char_set
return string

$conn_id public property

Connection ID
public object|resource $conn_id
return object | resource

$data_cache public property

An internal generic value cache.
public array $data_cache
return array

$database public property

Database name
public string $database
return string

$db_debug public property

Whether to display error messages.
public bool $db_debug
return boolean

$dbcollat public property

Collation
public string $dbcollat
return string

$dbdriver public property

Database driver
public string $dbdriver
return string

$dbprefix public property

Table prefix
public string $dbprefix
return string

$dsn public property

Data Source Name / Connect string
public string $dsn
return string

$encrypt public property

Encryption flag/data
public mixed $encrypt
return mixed

$hostname public property

Hostname
public string $hostname
return string

$password public property

Password
public string $password
return string

$pconnect public property

Persistent connection flag
public bool $pconnect
return boolean

$port public property

Database port
public int $port
return integer

$queries public property

Queries list
See also: CI_DB_driver::$save_queries
public string[] $queries
return string[]

$query_count public property

Executed queries count
public int $query_count
return integer

$query_times public property

A list of times that queries took to execute.
public array $query_times
return array

$result_id public property

Result ID
public object|resource $result_id
return object | resource

$save_queries public property

Whether to keep an in-memory history of queries for debugging purposes.
public bool $save_queries
return boolean

$subdriver public property

Sub-driver
public string $subdriver
return string

$swap_pre public property

Swap Prefix
public string $swap_pre
return string

$trans_enabled public property

Transaction enabled flag
public bool $trans_enabled
return boolean

$trans_strict public property

Strict transaction mode flag
public bool $trans_strict
return boolean

$username public property

Username
public string $username
return string