Class CI_DB_active_record - echiong/testRepo GitHub Wiki
##Class CI_DB_active_record
Active Record Class
This is the platform-independent base Active Record implementation class.
Package: [[CodeIgniter<a href="Package CodeIgniter.Drivers.md">Drivers]]
Category:
Database
Author:
ExpressionEngine Dev Team
Link:
http://codeigniter.com/user_guide/database/
Located at system/database/DB_active_rec.php
##Methods summary
public object select ( string $select = '*', mixed $escape = NULL )
Select
Generates the SELECT portion of the query
Parameters
$select
string
$escape
Returns
object
public object select_max ( string $select = '', string $alias = '' )
Select Max
Generates a SELECT MAX(field) portion of a query
Parameters
$select
string
the field
$alias
string
an alias
Returns
object
public object select_min ( string $select = '', string $alias = '' )
Select Min
Generates a SELECT MIN(field) portion of a query
Parameters
$select
string
the field
$alias
string
an alias
Returns
object
public object select_avg ( string $select = '', string $alias = '' )
Select Average
Generates a SELECT AVG(field) portion of a query
Parameters
$select
string
the field
$alias
string
an alias
Returns
object
public object select_sum ( string $select = '', string $alias = '' )
Select Sum
Generates a SELECT SUM(field) portion of a query
Parameters
$select
string
the field
$alias
string
an alias
Returns
object
protected object _max_min_avg_sum ( string $select = '', string $alias = '', mixed $type = 'MAX' )
Processing Function for the four functions above:
select_max() select_min() select_avg() select_sum()
Parameters
$select
string
the field
$alias
string
an alias
$type
Returns
object
protected string _create_alias_from_table ( string $item )
Determines the alias name based on the table
Parameters
$item
string
Returns
string
public object distinct ( boolean $val = TRUE )
DISTINCT
Sets a flag which tells the query string compiler to add DISTINCT
Parameters
$val
boolean
Returns
object
public object from ( mixed $from )
From
Generates the FROM portion of the query
Parameters
$from
mixed
can be a string or array
Returns
object
public object join ( string $table, string $cond, string $type = '' )
Join
Generates the JOIN portion of the query
Parameters
$table
string
$cond
string
the join condition
$type
string
the type of join
Returns
object
public object where ( mixed $key, mixed $value = NULL, mixed $escape = TRUE )
Where
Generates the WHERE portion of the query. Separates multiple calls with AND
Parameters
$key
mixed
$value
mixed
$escape
Returns
object
public object or_where ( mixed $key, mixed $value = NULL, mixed $escape = TRUE )
OR Where
Generates the WHERE portion of the query. Separates multiple calls with OR
Parameters
$key
mixed
$value
mixed
$escape
Returns
object
protected object _where ( mixed $key, mixed $value = NULL, string $type = 'AND ', mixed $escape = NULL )
Where
Called by where() or or_where()
Parameters
$key
mixed
$value
mixed
$type
string
$escape
Returns
object
public object where_in ( string $key = NULL, array $values = NULL )
Where_in
Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate
Parameters
$key
string
The field to search
$values
array
The values searched on
Returns
object
public object or_where_in ( string $key = NULL, array $values = NULL )
Where_in_or
Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate
Parameters
$key
string
The field to search
$values
array
The values searched on
Returns
object
public object where_not_in ( string $key = NULL, array $values = NULL )
Where_not_in
Generates a WHERE field NOT IN ('item', 'item') SQL query joined with AND if appropriate
Parameters
$key
string
The field to search
$values
array
The values searched on
Returns
object
public object or_where_not_in ( string $key = NULL, array $values = NULL )
Where_not_in_or
Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR if appropriate
Parameters
$key
string
The field to search
$values
array
The values searched on
Returns
object
protected object _where_in ( string $key = NULL, array $values = NULL, boolean $not = FALSE, string $type = 'AND ' )
Where_in
Called by where_in, where_in_or, where_not_in, where_not_in_or
Parameters
$key
string
The field to search
$values
array
The values searched on
$not
boolean
If the statement would be IN or NOT IN
$type
string
Returns
object
public object like ( mixed $field, mixed $match = '', mixed $side = 'both' )
Like
Generates a %LIKE% portion of the query. Separates multiple calls with AND
Parameters
$field
mixed
$match
mixed
$side
Returns
object
public object not_like ( mixed $field, mixed $match = '', mixed $side = 'both' )
Not Like
Generates a NOT LIKE portion of the query. Separates multiple calls with AND
Parameters
$field
mixed
$match
mixed
$side
Returns
object
public object or_like ( mixed $field, mixed $match = '', mixed $side = 'both' )
OR Like
Generates a %LIKE% portion of the query. Separates multiple calls with OR
Parameters
$field
mixed
$match
mixed
$side
Returns
object
public object or_not_like ( mixed $field, mixed $match = '', mixed $side = 'both' )
OR Not Like
Generates a NOT LIKE portion of the query. Separates multiple calls with OR
Parameters
$field
mixed
$match
mixed
$side
Returns
object
protected object _like ( mixed $field, mixed $match = '', string $type = 'AND ', mixed $side = 'both', mixed $not = '' )
Like
Called by like() or orlike()
Parameters
$field
mixed
$match
mixed
$type
string
$side
$not
Returns
object
public object group_by ( string $by )
GROUP BY
Parameters
$by
string
Returns
object
public object having ( string $key, string $value = '', mixed $escape = TRUE )
Sets the HAVING value
Separates multiple calls with AND
Parameters
$key
string
$value
string
$escape
Returns
object
public object or_having ( string $key, string $value = '', mixed $escape = TRUE )
Sets the OR HAVING value
Separates multiple calls with OR
Parameters
$key
string
$value
string
$escape
Returns
object
protected object _having ( string $key, string $value = '', mixed $type = 'AND ', mixed $escape = TRUE )
Sets the HAVING values
Called by having() or or_having()
Parameters
$key
string
$value
string
$type
$escape
Returns
object
public object order_by ( string $orderby, string $direction = '' )
Sets the ORDER BY value
Parameters
$orderby
string
$direction
string
direction: asc or desc
Returns
object
public object limit ( integer $value, integer $offset = '' )
Sets the LIMIT value
Parameters
$value
integer
the limit value
$offset
integer
the offset value
Returns
object
public object offset ( integer $offset )
Sets the OFFSET value
Parameters
$offset
integer
the offset value
Returns
object
public object set ( mixed $key, string $value = '', boolean $escape = TRUE )
The "set" function. Allows key/value pairs to be set for inserting or updating
Parameters
$key
mixed
$value
string
$escape
boolean
Returns
object
public object get ( string $table = '', string $limit = null, string $offset = null )
Get
Compiles the select statement based on the other functions called and runs the query
Parameters
$table
string
the table
$limit
string
the limit clause
$offset
string
the offset clause
Returns
object
public string count_all_results ( string $table = '' )
"Count All Results" query
Generates a platform-specific query string that counts all records returned by an Active Record query.
Parameters
$table
string
Returns
string
public object get_where ( string $table = '', string $where = null, string $limit = null, mixed $offset = null )
Get_Where
Allows the where clause, limit and offset to be added directly
Parameters
$table
string
the where clause
$where
string
the limit clause
$limit
string
the offset clause
$offset
Returns
object
public object insert_batch ( string $table = '', array $set = NULL )
Insert_Batch
Compiles batch insert strings and runs the queries
Parameters
$table
string
the table to retrieve the results from
$set
array
an associative array of insert values
Returns
object
public object set_insert_batch ( mixed $key, string $value = '', boolean $escape = TRUE )
The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
Parameters
$key
mixed
$value
string
$escape
boolean
Returns
object
public object insert ( string $table = '', array $set = NULL )
Insert
Compiles an insert string and runs the query
Parameters
$table
string
the table to insert data into
$set
array
an associative array of insert values
Returns
object
public object replace ( string $table = '', array $set = NULL )
Replace
Compiles an replace into string and runs the query
Parameters
$table
string
the table to replace data into
$set
array
an associative array of insert values
Returns
object
public object update ( string $table = '', array $set = NULL, mixed $where = NULL, mixed $limit = NULL )
Update
Compiles an update string and runs the query
Parameters
$table
string
the table to retrieve the results from
$set
array
an associative array of update values
$where
mixed
the where clause
$limit
Returns
object
public object update_batch ( string $table = '', array $set = NULL, string $index = NULL )
Update_Batch
Compiles an update string and runs the query
Parameters
$table
string
the table to retrieve the results from
$set
array
an associative array of update values
$index
string
the where key
Returns
object
public object set_update_batch ( array $key, string $index = '', boolean $escape = TRUE )
The "set_update_batch" function. Allows key/value pairs to be set for batch updating
Parameters
$key
array
$index
string
$escape
boolean
Returns
object
public object empty_table ( string $table = '' )
Empty Table
Compiles a delete string and runs "DELETE FROM table"
Parameters
$table
string
the table to empty
Returns
object
public object truncate ( string $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"
Parameters
$table
string
the table to truncate
Returns
object
public object delete ( mixed $table = '', mixed $where = '', mixed $limit = NULL, boolean $reset_data = TRUE )
Delete
Compiles a delete string and runs the query
Parameters
$table
mixed
the table(s) to delete from. String or array
$where
mixed
the where clause
$limit
mixed
the limit clause
$reset_data
boolean
Returns
object
public string dbprefix ( string $table = '' )
DB Prefix
Prepends a database prefix if one exists in configuration
Parameters
$table
string
the table
Returns
string
public string set_dbprefix ( string $prefix = '' )
Set DB Prefix
Set's the DB Prefix to something new without needing to reconnect
Parameters
$prefix
string
the prefix
Returns
string
protected string _track_aliases ( string $table )
Track Aliases
Used to track SQL statements written with aliased tables.
Parameters
$table
string
The table to inspect
Returns
string
protected string _compile_select ( mixed $select_override = FALSE )
Compile the SELECT statement
Generates a query string based on which functions were used. Should not be called directly. The get() function calls it.
Returns
string
public array _object_to_array ( object $object )
Object to Array
Takes an object as input and converts the class variables to array key/vals
Parameters
$object
object
Returns
array
public array _object_to_array_batch ( object $object )
Object to Array
Takes an object as input and converts the class variables to array key/vals
Parameters
$object
object
Returns
array
public start_cache ( )
Start Cache
Starts AR caching
public stop_cache ( )
Stop Cache
Stops AR caching
public flush_cache ( )
Flush Cache
Empties the AR cache
protected _merge_cache ( )
Merge Cache
When called, this function merges any cached AR arrays with locally called ones.
protected _reset_run ( array $ar_reset_items )
Resets the active record values. Called by the get() function
Parameters
$ar_reset_items
array
An array of fields to reset
protected _reset_select ( )
Resets the active record values. Called by the get() function
protected _reset_write ( )
Resets the active record "write" values.
Called by the insert() update() insert_batch() update_batch() and delete() functions
Methods inherited from CI_DB_driver
__construct()
_cache_init()
_has_operator()
_protect_identifiers()
cache_delete()
cache_delete_all()
cache_off()
cache_on()
cache_set_path()
call_function()
close()
compile_binds()
db_set_charset()
display_error()
elapsed_time()
escape()
escape_like_str()
field_data()
field_exists()
initialize()
insert_string()
is_write_type()
last_query()
list_fields()
list_tables()
load_rdriver()
platform()
primary()
protect_identifiers()
query()
simple_query()
table_exists()
total_queries()
trans_complete()
trans_off()
trans_start()
trans_status()
trans_strict()
update_string()
version()
<table class="summary" id="properties">
<caption>Properties summary</caption>
<tr data-order="ar_select" id="$ar_select">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_select
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_distinct" id="$ar_distinct">
<td class="attributes"><code>
public
boolean
</code></td>
<td class="name">
$ar_distinct
FALSE
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_from" id="$ar_from">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_from
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_join" id="$ar_join">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_join
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_where" id="$ar_where">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_where
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_like" id="$ar_like">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_like
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_groupby" id="$ar_groupby">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_groupby
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_having" id="$ar_having">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_having
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_keys" id="$ar_keys">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_keys
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_limit" id="$ar_limit">
<td class="attributes"><code>
public
boolean
</code></td>
<td class="name">
$ar_limit
FALSE
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_offset" id="$ar_offset">
<td class="attributes"><code>
public
boolean
</code></td>
<td class="name">
$ar_offset
FALSE
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_order" id="$ar_order">
<td class="attributes"><code>
public
boolean
</code></td>
<td class="name">
$ar_order
FALSE
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_orderby" id="$ar_orderby">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_orderby
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_set" id="$ar_set">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_set
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_wherein" id="$ar_wherein">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_wherein
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_aliased_tables" id="$ar_aliased_tables">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_aliased_tables
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_store_array" id="$ar_store_array">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_store_array
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_caching" id="$ar_caching">
<td class="attributes"><code>
public
boolean
</code></td>
<td class="name">
$ar_caching
FALSE
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_exists" id="$ar_cache_exists">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_exists
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_select" id="$ar_cache_select">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_select
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_from" id="$ar_cache_from">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_from
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_join" id="$ar_cache_join">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_join
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_where" id="$ar_cache_where">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_where
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_like" id="$ar_cache_like">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_like
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_groupby" id="$ar_cache_groupby">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_groupby
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_having" id="$ar_cache_having">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_having
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_orderby" id="$ar_cache_orderby">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_orderby
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_set" id="$ar_cache_set">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_set
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_no_escape" id="$ar_no_escape">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_no_escape
array()
<div class="description detailed">
</div>
</div></td>
</tr>
<tr data-order="ar_cache_no_escape" id="$ar_cache_no_escape">
<td class="attributes"><code>
public
array
</code></td>
<td class="name">
$ar_cache_no_escape
array()
<div class="description detailed">
</div>
</div></td>
</tr>
</table>
<table class="summary inherited">
<caption>Properties inherited from <a href="Class CI_DB_driver.md#properties">CI_DB_driver</a></caption>
<tr>
<td><code>
<a href="Class CI_DB_driver.md#$CACHE"><var>$CACHE</var></a>,
<a href="Class CI_DB_driver.md#$_protect_identifiers"><var>$_protect_identifiers</var></a>,
<a href="Class CI_DB_driver.md#$_reserved_identifiers"><var>$_reserved_identifiers</var></a>,
<a href="Class CI_DB_driver.md#$_trans_depth"><var>$_trans_depth</var></a>,
<a href="Class CI_DB_driver.md#$_trans_status"><var>$_trans_status</var></a>,
<a href="Class CI_DB_driver.md#$autoinit"><var>$autoinit</var></a>,
<a href="Class CI_DB_driver.md#$benchmark"><var>$benchmark</var></a>,
<a href="Class CI_DB_driver.md#$bind_marker"><var>$bind_marker</var></a>,
<a href="Class CI_DB_driver.md#$cache_autodel"><var>$cache_autodel</var></a>,
<a href="Class CI_DB_driver.md#$cache_on"><var>$cache_on</var></a>,
<a href="Class CI_DB_driver.md#$cachedir"><var>$cachedir</var></a>,
<a href="Class CI_DB_driver.md#$char_set"><var>$char_set</var></a>,
<a href="Class CI_DB_driver.md#$conn_id"><var>$conn_id</var></a>,
<a href="Class CI_DB_driver.md#$curs_id"><var>$curs_id</var></a>,
<a href="Class CI_DB_driver.md#$data_cache"><var>$data_cache</var></a>,
<a href="Class CI_DB_driver.md#$database"><var>$database</var></a>,
<a href="Class CI_DB_driver.md#$db_debug"><var>$db_debug</var></a>,
<a href="Class CI_DB_driver.md#$dbcollat"><var>$dbcollat</var></a>,
<a href="Class CI_DB_driver.md#$dbdriver"><var>$dbdriver</var></a>,
<a href="Class CI_DB_driver.md#$dbprefix"><var>$dbprefix</var></a>,
<a href="Class CI_DB_driver.md#$hostname"><var>$hostname</var></a>,
<a href="Class CI_DB_driver.md#$limit_used"><var>$limit_used</var></a>,
<a href="Class CI_DB_driver.md#$password"><var>$password</var></a>,
<a href="Class CI_DB_driver.md#$pconnect"><var>$pconnect</var></a>,
<a href="Class CI_DB_driver.md#$port"><var>$port</var></a>,
<a href="Class CI_DB_driver.md#$queries"><var>$queries</var></a>,
<a href="Class CI_DB_driver.md#$query_count"><var>$query_count</var></a>,
<a href="Class CI_DB_driver.md#$query_times"><var>$query_times</var></a>,
<a href="Class CI_DB_driver.md#$result_id"><var>$result_id</var></a>,
<a href="Class CI_DB_driver.md#$save_queries"><var>$save_queries</var></a>,
<a href="Class CI_DB_driver.md#$stmt_id"><var>$stmt_id</var></a>,
<a href="Class CI_DB_driver.md#$swap_pre"><var>$swap_pre</var></a>,
<a href="Class CI_DB_driver.md#$trans_enabled"><var>$trans_enabled</var></a>,
<a href="Class CI_DB_driver.md#$trans_strict"><var>$trans_strict</var></a>,
<a href="Class CI_DB_driver.md#$username"><var>$username</var></a>
</code></td>
</tr>
</table>