CI_DB_query_builder =============== Query Builder Class This is the platform-independent base Query Builder implementation class. * Class name: CI_DB_query_builder * Namespace: * This is an **abstract** class * Parent class: [CI_DB_driver](CI_DB_driver.md) Properties ---------- ### $return_delete_sql protected boolean $return_delete_sql = FALSE Return DELETE SQL flag * Visibility: **protected** ### $reset_delete_data protected boolean $reset_delete_data = FALSE Reset DELETE data flag * Visibility: **protected** ### $qb_select protected array $qb_select = array() QB SELECT data * Visibility: **protected** ### $qb_distinct protected boolean $qb_distinct = FALSE QB DISTINCT flag * Visibility: **protected** ### $qb_from protected array $qb_from = array() QB FROM data * Visibility: **protected** ### $qb_join protected array $qb_join = array() QB JOIN data * Visibility: **protected** ### $qb_where protected array $qb_where = array() QB WHERE data * Visibility: **protected** ### $qb_groupby protected array $qb_groupby = array() QB GROUP BY data * Visibility: **protected** ### $qb_having protected array $qb_having = array() QB HAVING data * Visibility: **protected** ### $qb_keys protected array $qb_keys = array() QB keys * Visibility: **protected** ### $qb_limit protected integer $qb_limit = FALSE QB LIMIT data * Visibility: **protected** ### $qb_offset protected integer $qb_offset = FALSE QB OFFSET data * Visibility: **protected** ### $qb_orderby protected array $qb_orderby = array() QB ORDER BY data * Visibility: **protected** ### $qb_set protected array $qb_set = array() QB data sets * Visibility: **protected** ### $qb_aliased_tables protected array $qb_aliased_tables = array() QB aliased tables list * Visibility: **protected** ### $qb_where_group_started protected boolean $qb_where_group_started = FALSE QB WHERE group started flag * Visibility: **protected** ### $qb_where_group_count protected integer $qb_where_group_count QB WHERE group count * Visibility: **protected** ### $qb_caching protected boolean $qb_caching = FALSE QB Caching flag * Visibility: **protected** ### $qb_cache_exists protected array $qb_cache_exists = array() QB Cache exists list * Visibility: **protected** ### $qb_cache_select protected array $qb_cache_select = array() QB Cache SELECT data * Visibility: **protected** ### $qb_cache_from protected array $qb_cache_from = array() QB Cache FROM data * Visibility: **protected** ### $qb_cache_join protected array $qb_cache_join = array() QB Cache JOIN data * Visibility: **protected** ### $qb_cache_where protected array $qb_cache_where = array() QB Cache WHERE data * Visibility: **protected** ### $qb_cache_groupby protected array $qb_cache_groupby = array() QB Cache GROUP BY data * Visibility: **protected** ### $qb_cache_having protected array $qb_cache_having = array() QB Cache HAVING data * Visibility: **protected** ### $qb_cache_orderby protected array $qb_cache_orderby = array() QB Cache ORDER BY data * Visibility: **protected** ### $qb_cache_set protected array $qb_cache_set = array() QB Cache data sets * Visibility: **protected** ### $qb_no_escape protected array $qb_no_escape = array() QB No Escape data * Visibility: **protected** ### $qb_cache_no_escape protected array $qb_cache_no_escape = array() QB Cache No Escape data * Visibility: **protected** ### $dsn public string $dsn Data Source Name / Connect string * Visibility: **public** ### $username public string $username Username * Visibility: **public** ### $password public string $password Password * Visibility: **public** ### $hostname public string $hostname Hostname * Visibility: **public** ### $database public string $database Database name * Visibility: **public** ### $dbdriver public string $dbdriver = 'mysqli' Database driver * Visibility: **public** ### $subdriver public string $subdriver Sub-driver * Visibility: **public** ### $dbprefix public string $dbprefix = '' Table prefix * Visibility: **public** ### $char_set public string $char_set = 'utf8' Character set * Visibility: **public** ### $dbcollat public string $dbcollat = 'utf8_general_ci' Collation * Visibility: **public** ### $encrypt public mixed $encrypt = FALSE Encryption flag/data * Visibility: **public** ### $swap_pre public string $swap_pre = '' Swap Prefix * Visibility: **public** ### $port public integer $port = '' Database port * Visibility: **public** ### $pconnect public boolean $pconnect = FALSE Persistent connection flag * Visibility: **public** ### $conn_id public object $conn_id = FALSE Connection ID * Visibility: **public** ### $result_id public object $result_id = FALSE Result ID * Visibility: **public** ### $db_debug public boolean $db_debug = FALSE Debug flag Whether to display error messages. * Visibility: **public** ### $benchmark public integer $benchmark Benchmark time * Visibility: **public** ### $query_count public integer $query_count Executed queries count * Visibility: **public** ### $bind_marker public string $bind_marker = '?' Bind marker Character used to identify values in a prepared statement. * Visibility: **public** ### $save_queries public boolean $save_queries = TRUE Save queries flag Whether to keep an in-memory history of queries for debugging purposes. * Visibility: **public** ### $queries public array $queries = array() Queries list * Visibility: **public** ### $query_times public array $query_times = array() Query times A list of times that queries took to execute. * Visibility: **public** ### $data_cache public array $data_cache = array() Data cache An internal generic value cache. * Visibility: **public** ### $trans_enabled public boolean $trans_enabled = TRUE Transaction enabled flag * Visibility: **public** ### $trans_strict public boolean $trans_strict = TRUE Strict transaction mode flag * Visibility: **public** ### $_trans_depth protected integer $_trans_depth Transaction depth level * Visibility: **protected** ### $_trans_status protected boolean $_trans_status = TRUE Transaction status flag Used with transactions to determine if a rollback should occur. * Visibility: **protected** ### $_trans_failure protected boolean $_trans_failure = FALSE Transaction failure flag Used with transactions to determine if a transaction has failed. * Visibility: **protected** ### $cache_on public boolean $cache_on = FALSE Cache On flag * Visibility: **public** ### $cachedir public boolean $cachedir = '' Cache directory path * Visibility: **public** ### $cache_autodel public boolean $cache_autodel = FALSE Cache auto-delete flag * Visibility: **public** ### $CACHE public object $CACHE DB Cache object * Visibility: **public** ### $_protect_identifiers protected boolean $_protect_identifiers = TRUE Protect identifiers flag * Visibility: **protected** ### $_reserved_identifiers protected array $_reserved_identifiers = array('*') List of reserved identifiers Identifiers that must NOT be escaped. * Visibility: **protected** ### $_escape_char protected string $_escape_char = '"' Identifier escape character * Visibility: **protected** ### $_like_escape_str protected string $_like_escape_str = " ESCAPE '%s' " ESCAPE statement string * Visibility: **protected** ### $_like_escape_chr protected string $_like_escape_chr = '!' ESCAPE character * Visibility: **protected** ### $_random_keyword protected array $_random_keyword = array('RAND()', 'RAND(%d)') ORDER BY random keyword * Visibility: **protected** ### $_count_string protected string $_count_string = 'SELECT COUNT(*) AS ' COUNT string * Visibility: **protected** Methods ------- ### select \CI_DB_query_builder CI_DB_query_builder::select($select, $escape) Select Generates the SELECT portion of the query * Visibility: **public** #### Arguments * $select **mixed** * $escape **mixed** ### select_max \CI_DB_query_builder CI_DB_query_builder::select_max($select, $alias) Select Max Generates a SELECT MAX(field) portion of a query * Visibility: **public** #### Arguments * $select **mixed** * $alias **mixed** ### select_min \CI_DB_query_builder CI_DB_query_builder::select_min($select, $alias) Select Min Generates a SELECT MIN(field) portion of a query * Visibility: **public** #### Arguments * $select **mixed** * $alias **mixed** ### select_avg \CI_DB_query_builder CI_DB_query_builder::select_avg($select, $alias) Select Average Generates a SELECT AVG(field) portion of a query * Visibility: **public** #### Arguments * $select **mixed** * $alias **mixed** ### select_sum \CI_DB_query_builder CI_DB_query_builder::select_sum($select, $alias) Select Sum Generates a SELECT SUM(field) portion of a query * Visibility: **public** #### Arguments * $select **mixed** * $alias **mixed** ### _max_min_avg_sum \CI_DB_query_builder CI_DB_query_builder::_max_min_avg_sum(string $select, string $alias, string $type) SELECT [MAX|MIN|AVG|SUM]() * Visibility: **protected** #### Arguments * $select **string** - <p>Field name</p> * $alias **string** * $type **string** ### _create_alias_from_table string CI_DB_query_builder::_create_alias_from_table(string $item) Determines the alias name based on the table * Visibility: **protected** #### Arguments * $item **string** ### distinct \CI_DB_query_builder CI_DB_query_builder::distinct(boolean $val) DISTINCT Sets a flag which tells the query string compiler to add DISTINCT * Visibility: **public** #### Arguments * $val **boolean** ### from \CI_DB_query_builder CI_DB_query_builder::from(mixed $from) From Generates the FROM portion of the query * Visibility: **public** #### Arguments * $from **mixed** - <p>can be a string or array</p> ### join \CI_DB_query_builder CI_DB_query_builder::join($table, $cond, $type, $escape) JOIN Generates the JOIN portion of the query * Visibility: **public** #### Arguments * $table **mixed** * $cond **mixed** * $type **mixed** * $escape **mixed** ### where \CI_DB_query_builder CI_DB_query_builder::where($key, $value, $escape) WHERE Generates the WHERE portion of the query. Separates multiple calls with 'AND'. * Visibility: **public** #### Arguments * $key **mixed** * $value **mixed** * $escape **mixed** ### or_where \CI_DB_query_builder CI_DB_query_builder::or_where($key, $value, $escape) OR WHERE Generates the WHERE portion of the query. Separates multiple calls with 'OR'. * Visibility: **public** #### Arguments * $key **mixed** * $value **mixed** * $escape **mixed** ### _wh \CI_DB_query_builder CI_DB_query_builder::_wh(string $qb_key, mixed $key, mixed $value, string $type, boolean $escape) WHERE, HAVING * Visibility: **protected** #### Arguments * $qb_key **string** - <p>'qb_where' or 'qb_having'</p> * $key **mixed** * $value **mixed** * $type **string** * $escape **boolean** ### where_in \CI_DB_query_builder CI_DB_query_builder::where_in(string $key, array $values, boolean $escape) WHERE IN Generates a WHERE field IN('item', 'item') SQL query, joined with 'AND' if appropriate. * Visibility: **public** #### Arguments * $key **string** - <p>The field to search</p> * $values **array** - <p>The values searched on</p> * $escape **boolean** ### or_where_in \CI_DB_query_builder CI_DB_query_builder::or_where_in(string $key, array $values, boolean $escape) OR WHERE IN Generates a WHERE field IN('item', 'item') SQL query, joined with 'OR' if appropriate. * Visibility: **public** #### Arguments * $key **string** - <p>The field to search</p> * $values **array** - <p>The values searched on</p> * $escape **boolean** ### where_not_in \CI_DB_query_builder CI_DB_query_builder::where_not_in(string $key, array $values, boolean $escape) WHERE NOT IN Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'AND' if appropriate. * Visibility: **public** #### Arguments * $key **string** - <p>The field to search</p> * $values **array** - <p>The values searched on</p> * $escape **boolean** ### or_where_not_in \CI_DB_query_builder CI_DB_query_builder::or_where_not_in(string $key, array $values, boolean $escape) OR WHERE NOT IN Generates a WHERE field NOT IN('item', 'item') SQL query, joined with 'OR' if appropriate. * Visibility: **public** #### Arguments * $key **string** - <p>The field to search</p> * $values **array** - <p>The values searched on</p> * $escape **boolean** ### _where_in \CI_DB_query_builder CI_DB_query_builder::_where_in(string $key, array $values, boolean $not, string $type, boolean $escape) Internal WHERE IN * Visibility: **protected** #### Arguments * $key **string** - <p>The field to search</p> * $values **array** - <p>The values searched on</p> * $not **boolean** - <p>If the statement would be IN or NOT IN</p> * $type **string** * $escape **boolean** ### like \CI_DB_query_builder CI_DB_query_builder::like(mixed $field, string $match, string $side, boolean $escape) LIKE Generates a %LIKE% portion of the query. Separates multiple calls with 'AND'. * Visibility: **public** #### Arguments * $field **mixed** * $match **string** * $side **string** * $escape **boolean** ### not_like \CI_DB_query_builder CI_DB_query_builder::not_like(mixed $field, string $match, string $side, boolean $escape) NOT LIKE Generates a NOT LIKE portion of the query. Separates multiple calls with 'AND'. * Visibility: **public** #### Arguments * $field **mixed** * $match **string** * $side **string** * $escape **boolean** ### or_like \CI_DB_query_builder CI_DB_query_builder::or_like(mixed $field, string $match, string $side, boolean $escape) OR LIKE Generates a %LIKE% portion of the query. Separates multiple calls with 'OR'. * Visibility: **public** #### Arguments * $field **mixed** * $match **string** * $side **string** * $escape **boolean** ### or_not_like \CI_DB_query_builder CI_DB_query_builder::or_not_like(mixed $field, string $match, string $side, boolean $escape) OR NOT LIKE Generates a NOT LIKE portion of the query. Separates multiple calls with 'OR'. * Visibility: **public** #### Arguments * $field **mixed** * $match **string** * $side **string** * $escape **boolean** ### _like \CI_DB_query_builder CI_DB_query_builder::_like(mixed $field, string $match, string $type, string $side, string $not, boolean $escape) Internal LIKE * Visibility: **protected** #### Arguments * $field **mixed** * $match **string** * $type **string** * $side **string** * $not **string** * $escape **boolean** ### group_start \CI_DB_query_builder CI_DB_query_builder::group_start(string $not, string $type) Starts a query group. * Visibility: **public** #### Arguments * $not **string** - <p>(Internal use only)</p> * $type **string** - <p>(Internal use only)</p> ### or_group_start \CI_DB_query_builder CI_DB_query_builder::or_group_start() Starts a query group, but ORs the group * Visibility: **public** ### not_group_start \CI_DB_query_builder CI_DB_query_builder::not_group_start() Starts a query group, but NOTs the group * Visibility: **public** ### or_not_group_start \CI_DB_query_builder CI_DB_query_builder::or_not_group_start() Starts a query group, but OR NOTs the group * Visibility: **public** ### group_end \CI_DB_query_builder CI_DB_query_builder::group_end() Ends a query group * Visibility: **public** ### _group_get_type string CI_DB_query_builder::_group_get_type(string $type) Group_get_type * Visibility: **protected** #### Arguments * $type **string** ### group_by \CI_DB_query_builder CI_DB_query_builder::group_by(string $by, boolean $escape) GROUP BY * Visibility: **public** #### Arguments * $by **string** * $escape **boolean** ### having object CI_DB_query_builder::having(string $key, string $value, boolean $escape) HAVING Separates multiple calls with 'AND'. * Visibility: **public** #### Arguments * $key **string** * $value **string** * $escape **boolean** ### or_having object CI_DB_query_builder::or_having(string $key, string $value, boolean $escape) OR HAVING Separates multiple calls with 'OR'. * Visibility: **public** #### Arguments * $key **string** * $value **string** * $escape **boolean** ### order_by \CI_DB_query_builder CI_DB_query_builder::order_by(string $orderby, string $direction, boolean $escape) ORDER BY * Visibility: **public** #### Arguments * $orderby **string** * $direction **string** - <p>ASC, DESC or RANDOM</p> * $escape **boolean** ### limit \CI_DB_query_builder CI_DB_query_builder::limit(integer $value, integer $offset) LIMIT * Visibility: **public** #### Arguments * $value **integer** - <p>LIMIT value</p> * $offset **integer** - <p>OFFSET value</p> ### offset \CI_DB_query_builder CI_DB_query_builder::offset(integer $offset) Sets the OFFSET value * Visibility: **public** #### Arguments * $offset **integer** - <p>OFFSET value</p> ### _limit string CI_DB_query_builder::_limit(string $sql) LIMIT string Generates a platform-specific LIMIT clause. * Visibility: **protected** #### Arguments * $sql **string** - <p>SQL Query</p> ### set \CI_DB_query_builder CI_DB_query_builder::set($key, $value, $escape) The "set" function. Allows key/value pairs to be set for inserting or updating * Visibility: **public** #### Arguments * $key **mixed** * $value **mixed** * $escape **mixed** ### get_compiled_select string CI_DB_query_builder::get_compiled_select($table, $reset) Get SELECT query string Compiles a SELECT query string and returns the sql. * Visibility: **public** #### Arguments * $table **mixed** * $reset **mixed** ### get object CI_DB_query_builder::get($table, $limit, $offset) Get Compiles the select statement based on the other functions called and runs the query * Visibility: **public** #### Arguments * $table **mixed** * $limit **mixed** * $offset **mixed** ### count_all_results integer CI_DB_query_builder::count_all_results($table, $reset) "Count All Results" query Generates a platform-specific query string that counts all records returned by an Query Builder query. * Visibility: **public** #### Arguments * $table **mixed** * $reset **mixed** ### get_where object CI_DB_query_builder::get_where(string $table, string $where, integer $limit, integer $offset) Get_Where Allows the where clause, limit and offset to be added directly * Visibility: **public** #### Arguments * $table **string** * $where **string** * $limit **integer** * $offset **integer** ### insert_batch integer CI_DB_query_builder::insert_batch(string $table, array $set, boolean $escape) Insert_Batch Compiles batch insert strings and runs the queries * Visibility: **public** #### Arguments * $table **string** - <p>Table to insert into</p> * $set **array** - <p>An associative array of insert values</p> * $escape **boolean** - <p>Whether to escape values and identifiers</p> ### _insert_batch string CI_DB_query_builder::_insert_batch(string $table, array $keys, array $values) Insert batch statement Generates a platform-specific insert string from the supplied data. * Visibility: **protected** #### Arguments * $table **string** - <p>Table name</p> * $keys **array** - <p>INSERT keys</p> * $values **array** - <p>INSERT values</p> ### set_insert_batch \CI_DB_query_builder CI_DB_query_builder::set_insert_batch($key, $value, $escape) The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts * Visibility: **public** #### Arguments * $key **mixed** * $value **mixed** * $escape **mixed** ### get_compiled_insert string CI_DB_query_builder::get_compiled_insert($table, $reset) Get INSERT query string Compiles an insert query and returns the sql * Visibility: **public** #### Arguments * $table **mixed** * $reset **mixed** ### insert object CI_DB_query_builder::insert($table, $set, boolean $escape) Insert Compiles an insert string and runs the query * Visibility: **public** #### Arguments * $table **mixed** * $set **mixed** * $escape **boolean** - <p>Whether to escape values and identifiers</p> ### _validate_insert string CI_DB_query_builder::_validate_insert($table) Validate Insert This method is used by both insert() and get_compiled_insert() to validate that the there data is actually being set and that table has been chosen to be inserted into. * Visibility: **protected** #### Arguments * $table **mixed** ### replace object CI_DB_query_builder::replace($table, $set) Replace Compiles an replace into string and runs the query * Visibility: **public** #### Arguments * $table **mixed** * $set **mixed** ### _replace string CI_DB_query_builder::_replace($table, $keys, $values) Replace statement Generates a platform-specific replace string from the supplied data * Visibility: **protected** #### Arguments * $table **mixed** * $keys **mixed** * $values **mixed** ### _from_tables string CI_DB_query_builder::_from_tables() FROM tables Groups tables in FROM clauses if needed, so there is no confusion about operator precedence. Note: This is only used (and overridden) by MySQL and CUBRID. * Visibility: **protected** ### get_compiled_update string CI_DB_query_builder::get_compiled_update($table, $reset) Get UPDATE query string Compiles an update query and returns the sql * Visibility: **public** #### Arguments * $table **mixed** * $reset **mixed** ### update object CI_DB_query_builder::update(string $table, array $set, mixed $where, integer $limit) UPDATE Compiles an update string and runs the query. * Visibility: **public** #### Arguments * $table **string** * $set **array** - <p>An associative array of update values</p> * $where **mixed** * $limit **integer** ### _validate_update boolean CI_DB_query_builder::_validate_update($table) Validate Update This method is used by both update() and get_compiled_update() to validate that data is actually being set and that a table has been chosen to be update. * Visibility: **protected** #### Arguments * $table **mixed** ### update_batch integer CI_DB_query_builder::update_batch($table, $set, $index) Update_Batch Compiles an update string and runs the query * Visibility: **public** #### Arguments * $table **mixed** * $set **mixed** * $index **mixed** ### _update_batch string CI_DB_query_builder::_update_batch(string $table, array $values, string $index) Update_Batch statement Generates a platform-specific batch update string from the supplied data * Visibility: **protected** #### Arguments * $table **string** - <p>Table name</p> * $values **array** - <p>Update data</p> * $index **string** - <p>WHERE key</p> ### set_update_batch \CI_DB_query_builder CI_DB_query_builder::set_update_batch($key, $index, $escape) The "set_update_batch" function. Allows key/value pairs to be set for batch updating * Visibility: **public** #### Arguments * $key **mixed** * $index **mixed** * $escape **mixed** ### empty_table object CI_DB_query_builder::empty_table($table) Empty Table Compiles a delete string and runs "DELETE FROM table" * Visibility: **public** #### Arguments * $table **mixed** ### truncate object CI_DB_query_builder::truncate($table) Truncate Compiles a truncate string and runs the query If the database does not support the truncate() command This function maps to "DELETE FROM table" * Visibility: **public** #### Arguments * $table **mixed** ### _truncate string CI_DB_query_builder::_truncate($table) Truncate statement Generates a platform-specific truncate string from the supplied data If the database does not support the truncate() command, then this method maps to 'DELETE FROM table' * Visibility: **protected** #### Arguments * $table **mixed** ### get_compiled_delete string CI_DB_query_builder::get_compiled_delete($table, $reset) Get DELETE query string Compiles a delete query string and returns the sql * Visibility: **public** #### Arguments * $table **mixed** * $reset **mixed** ### delete mixed CI_DB_query_builder::delete($table, $where, $limit, $reset_data) Delete Compiles a delete string and runs the query * Visibility: **public** #### Arguments * $table **mixed** * $where **mixed** * $limit **mixed** * $reset_data **mixed** ### _delete string CI_DB_query_builder::_delete($table) Delete statement Generates a platform-specific delete string from the supplied data * Visibility: **protected** #### Arguments * $table **mixed** ### dbprefix string CI_DB_query_builder::dbprefix($table) DB Prefix Prepends a database prefix if one exists in configuration * Visibility: **public** #### Arguments * $table **mixed** ### set_dbprefix string CI_DB_query_builder::set_dbprefix($prefix) Set DB Prefix Set's the DB Prefix to something new without needing to reconnect * Visibility: **public** #### Arguments * $prefix **mixed** ### _track_aliases string CI_DB_query_builder::_track_aliases($table) Track Aliases Used to track SQL statements written with aliased tables. * Visibility: **protected** #### Arguments * $table **mixed** ### _compile_select string CI_DB_query_builder::_compile_select(boolean $select_override) Compile the SELECT statement Generates a query string based on which functions were used. Should not be called directly. * Visibility: **protected** #### Arguments * $select_override **boolean** ### _compile_wh string CI_DB_query_builder::_compile_wh(string $qb_key) Compile WHERE, HAVING statements Escapes identifiers in WHERE and HAVING statements at execution time. Required so that aliases are tracked properly, regardless of wether where(), or_where(), having(), or_having are called prior to from(), join() and dbprefix is added only if needed. * Visibility: **protected** #### Arguments * $qb_key **string** - <p>'qb_where' or 'qb_having'</p> ### _compile_group_by string CI_DB_query_builder::_compile_group_by() Compile GROUP BY Escapes identifiers in GROUP BY statements at execution time. Required so that aliases are tracked properly, regardless of wether group_by() is called prior to from(), join() and dbprefix is added only if needed. * Visibility: **protected** ### _compile_order_by string CI_DB_query_builder::_compile_order_by() Compile ORDER BY Escapes identifiers in ORDER BY statements at execution time. Required so that aliases are tracked properly, regardless of wether order_by() is called prior to from(), join() and dbprefix is added only if needed. * Visibility: **protected** ### _object_to_array array CI_DB_query_builder::_object_to_array($object) Object to Array Takes an object as input and converts the class variables to array key/vals * Visibility: **protected** #### Arguments * $object **mixed** ### _object_to_array_batch array CI_DB_query_builder::_object_to_array_batch($object) Object to Array Takes an object as input and converts the class variables to array key/vals * Visibility: **protected** #### Arguments * $object **mixed** ### start_cache \CI_DB_query_builder CI_DB_query_builder::start_cache() Start Cache Starts QB caching * Visibility: **public** ### stop_cache \CI_DB_query_builder CI_DB_query_builder::stop_cache() Stop Cache Stops QB caching * Visibility: **public** ### flush_cache \CI_DB_query_builder CI_DB_query_builder::flush_cache() Flush Cache Empties the QB cache * Visibility: **public** ### _merge_cache void CI_DB_query_builder::_merge_cache() Merge Cache When called, this function merges any cached QB arrays with locally called ones. * Visibility: **protected** ### _is_literal boolean CI_DB_query_builder::_is_literal(string $str) Is literal Determines if a string represents a literal value or a field name * Visibility: **protected** #### Arguments * $str **string** ### reset_query \CI_DB_query_builder CI_DB_query_builder::reset_query() Reset Query Builder values. Publicly-visible method to reset the QB values. * Visibility: **public** ### _reset_run void CI_DB_query_builder::_reset_run($qb_reset_items) Resets the query builder values. Called by the get() function * Visibility: **protected** #### Arguments * $qb_reset_items **mixed** ### _reset_select void CI_DB_driver::_reset_select() Dummy method that allows Query Builder class to be disabled and keep count_all() working. * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### _reset_write void CI_DB_query_builder::_reset_write() Resets the query builder "write" values. Called by the insert() update() insert_batch() update_batch() and delete() functions * Visibility: **protected** ### __construct void CI_DB_driver::__construct(array $params) Class constructor * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $params **array** ### initialize boolean CI_DB_driver::initialize() Initialize Database Settings * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### db_connect mixed CI_DB_driver::db_connect() DB connect This is just a dummy method that all drivers will override. * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### db_pconnect mixed CI_DB_driver::db_pconnect() Persistent database connection * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### reconnect 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### db_select 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### db_set_charset boolean CI_DB_driver::db_set_charset($charset) Set client character set * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $charset **mixed** ### platform string CI_DB_driver::platform() The name of the platform in use (mysql, mssql, etc. ..) * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### version 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### _version string CI_DB_driver::_version() Version number query string * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### query 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $sql **string** * $binds **array** - <p>= FALSE An array of binding data</p> * $return_object **boolean** - <p>= NULL</p> ### load_rdriver string CI_DB_driver::load_rdriver() Load the result drivers * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### simple_query 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $sql **mixed** ### trans_off void CI_DB_driver::trans_off() Disable Transactions This permits transactions to be disabled at run-time. * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### trans_strict 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $mode **boolean** - <p>= TRUE</p> ### trans_start void CI_DB_driver::trans_start(boolean $test_mode) Start Transaction * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $test_mode **boolean** - <p>= FALSE</p> ### trans_complete boolean CI_DB_driver::trans_complete() Complete Transaction * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### trans_status boolean CI_DB_driver::trans_status() Lets you retrieve the transaction flag to determine if it has failed * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### compile_binds string CI_DB_driver::compile_binds($sql, $binds) Compile Bindings * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $sql **mixed** * $binds **mixed** ### is_write_type boolean CI_DB_driver::is_write_type($sql) Determines if a query is a "write" type. * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $sql **mixed** ### elapsed_time string CI_DB_driver::elapsed_time($decimals) Calculate the aggregate query elapsed time * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $decimals **mixed** ### total_queries integer CI_DB_driver::total_queries() Returns the total number of queries * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### last_query string CI_DB_driver::last_query() Returns the last query that was executed * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### escape mixed CI_DB_driver::escape($str) "Smart" Escape String Escapes data based on type Sets boolean and null types * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $str **mixed** ### escape_str string CI_DB_driver::escape_str(string|array $str, boolean $like) Escape String * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $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> ### escape_like_str mixed CI_DB_driver::escape_like_str($str) Escape LIKE String Calls the individual driver for platform specific escaping for LIKE conditions * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $str **mixed** ### _escape_str string CI_DB_driver::_escape_str($str) Platform-dependant string escape * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $str **mixed** ### primary 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **string** - <p>Table name</p> ### count_all 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **mixed** ### list_tables array CI_DB_driver::list_tables(string $constrain_by_prefix) Returns an array of table names * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $constrain_by_prefix **string** - <p>= FALSE</p> ### table_exists boolean CI_DB_driver::table_exists(string $table_name) Determine if a particular table exists * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table_name **string** ### list_fields array CI_DB_driver::list_fields(string $table) Fetch Field Names * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **string** - <p>Table name</p> ### field_exists boolean CI_DB_driver::field_exists($field_name, $table_name) Determine if a particular field exists * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $field_name **mixed** * $table_name **mixed** ### field_data array CI_DB_driver::field_data(string $table) Returns an object with field data * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **string** - <p>the table name</p> ### escape_identifiers mixed CI_DB_driver::escape_identifiers($item) Escape the SQL Identifiers This function escapes column and table names * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $item **mixed** ### insert_string string CI_DB_driver::insert_string($table, $data) Generate an insert string * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **mixed** * $data **mixed** ### _insert string CI_DB_driver::_insert($table, $keys, $values) Insert statement Generates a platform-specific insert string from the supplied data * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **mixed** * $keys **mixed** * $values **mixed** ### update_string string CI_DB_driver::update_string($table, $data, $where) Generate an update string * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **mixed** * $data **mixed** * $where **mixed** ### _update string CI_DB_driver::_update($table, $values) Update statement Generates a platform-specific update string from the supplied data * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $table **mixed** * $values **mixed** ### _has_operator boolean CI_DB_driver::_has_operator($str) Tests whether the string has an SQL operator * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $str **mixed** ### _get_operator string CI_DB_driver::_get_operator($str) Returns the SQL string operator * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $str **mixed** ### call_function mixed CI_DB_driver::call_function(string $function) Enables a native PHP function to be run, using a platform agnostic wrapper. * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $function **string** - <p>Function name</p> ### cache_set_path void CI_DB_driver::cache_set_path($path) Set Cache Directory Path * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $path **mixed** ### cache_on boolean CI_DB_driver::cache_on() Enable Query Caching * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### cache_off boolean CI_DB_driver::cache_off() Disable Query Caching * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### cache_delete boolean CI_DB_driver::cache_delete(string $segment_one, string $segment_two) Delete the cache files associated with a particular URI * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $segment_one **string** - <p>= ''</p> * $segment_two **string** - <p>= ''</p> ### cache_delete_all boolean CI_DB_driver::cache_delete_all() Delete All cache files * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### _cache_init boolean CI_DB_driver::_cache_init() Initialize the Cache Class * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### close void CI_DB_driver::close() Close DB Connection * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### _close void CI_DB_driver::_close() Close DB Connection This method would be overridden by most of the drivers. * Visibility: **protected** * This method is defined by [CI_DB_driver](CI_DB_driver.md) ### display_error string CI_DB_driver::display_error($error, $swap, $native) Display an error message * Visibility: **public** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $error **mixed** * $swap **mixed** * $native **mixed** ### protect_identifiers 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** * This method is defined by [CI_DB_driver](CI_DB_driver.md) #### Arguments * $item **mixed** * $prefix_single **mixed** * $protect_identifiers **mixed** * $field_exists **mixed**