PHP Class CI_DB_active_record, 68kb

This is the platform-independent base Active Record implementation class.
Author: ExpressionEngine Dev Team
Inheritance: extends CI_DB_driver
ファイルを表示 Open project: 68kb/68kb Class Usage Examples

Public Properties

Property Type Description
$ar_aliased_tables
$ar_cache_exists
$ar_cache_from
$ar_cache_groupby
$ar_cache_having
$ar_cache_join
$ar_cache_like
$ar_cache_orderby
$ar_cache_select
$ar_cache_set
$ar_cache_where
$ar_caching Active Record Caching variables
$ar_distinct
$ar_from
$ar_groupby
$ar_having
$ar_join
$ar_like
$ar_limit
$ar_offset
$ar_order
$ar_orderby
$ar_select
$ar_set
$ar_store_array
$ar_where
$ar_wherein

Public Methods

Method Description
_compile_select ( $select_override = FALSE ) : string Compile the SELECT statement
_create_alias_from_table ( $item ) : string Determines the alias name based on the table
_having ( $key, $value = '', $type = 'AND ', $escape = TRUE ) : object Sets the HAVING values
_like ( $field, $match = '', $type = 'AND ', $side = 'both', $not = '' ) : object Like
_max_min_avg_sum ( $select = '', $alias = '', $type = 'MAX' ) : object Processing Function for the four functions above:
_merge_cache ( ) : void Merge Cache
_object_to_array ( $object ) : array Object to Array
_object_to_array_batch ( $object ) : array Object to Array
_reset_run ( $ar_reset_items ) : void Resets the active record values. Called by the get() function
_reset_select ( ) : void Resets the active record values. Called by the get() function
_reset_write ( ) : void Resets the active record "write" values.
_track_aliases ( $table ) : string Track Aliases
_where ( $key, $value = NULL, $type = 'AND ', $escape = NULL ) : object Where
_where_in ( $key = NULL, $values = NULL, $not = FALSE, $type = 'AND ' ) : object Where_in
count_all_results ( $table = '' ) : string "Count All Results" query
dbprefix ( $table = '' ) : string DB Prefix
delete ( $table = '', $where = '', $limit = NULL, $reset_data = TRUE ) : object Delete
distinct ( $val = TRUE ) : object DISTINCT
empty_table ( $table = '' ) : object Empty Table
flush_cache ( ) : void Flush Cache
from ( $from ) : object From
get ( $table = '', $limit = null, $offset = null ) : object Get
get_where ( $table = '', $where = null, $limit = null, $offset = null ) : object Get_Where
getwhere ( $table = '', $where = null, $limit = null, $offset = null ) getwhere() is an alias of get_where() this function is here for backwards compatibility, as getwhere() has been deprecated
group_by ( $by ) : object GROUP BY
groupby ( $by ) groupby() is an alias of group_by() this function is here for backwards compatibility, as groupby() has been deprecated
having ( $key, $value = '', $escape = TRUE ) : object Sets the HAVING value
insert ( $table = '', $set = NULL ) : object Insert
insert_batch ( $table = '', $set = NULL ) : object Insert_Batch
join ( $table, $cond, $type = '' ) : object Join
like ( $field, $match = '', $side = 'both' ) : object Like
limit ( $value, $offset = '' ) : object Sets the LIMIT value
not_like ( $field, $match = '', $side = 'both' ) : object Not Like
offset ( $offset ) : object Sets the OFFSET value
or_having ( $key, $value = '', $escape = TRUE ) : object Sets the OR HAVING value
or_like ( $field, $match = '', $side = 'both' ) : object OR Like
or_not_like ( $field, $match = '', $side = 'both' ) : object OR Not Like
or_where ( $key, $value = NULL, $escape = TRUE ) : object OR Where
or_where_in ( $key = NULL, $values = NULL ) : object Where_in_or
or_where_not_in ( $key = NULL, $values = NULL ) : object Where_not_in_or
order_by ( $orderby, $direction = '' ) : object Sets the ORDER BY value
orderby ( $orderby, $direction = '' ) orderby() is an alias of order_by() this function is here for backwards compatibility, as orderby() has been deprecated
orhaving ( $key, $value = '', $escape = TRUE ) orhaving() is an alias of or_having() this function is here for backwards compatibility, as orhaving() has been deprecated
orlike ( $field, $match = '', $side = 'both' ) orlike() is an alias of or_like() this function is here for backwards compatibility, as orlike() has been deprecated
orwhere ( $key, $value = NULL, $escape = TRUE ) orwhere() is an alias of or_where() this function is here for backwards compatibility, as orwhere() has been deprecated
replace ( $table = '', $set = NULL )
select ( $select = '*', $escape = NULL ) : object Select
select_avg ( $select = '', $alias = '' ) : object Select Average
select_max ( $select = '', $alias = '' ) : object Select Max
select_min ( $select = '', $alias = '' ) : object Select Min
select_sum ( $select = '', $alias = '' ) : object Select Sum
set ( $key, $value = '', $escape = TRUE ) : object The "set" function. Allows key/value pairs to be set for inserting or updating
set_insert_batch ( $key, $value = '', $escape = TRUE ) : object The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
set_update_batch ( $key, $index = '', $escape = TRUE ) : object The "set_update_batch" function. Allows key/value pairs to be set for batch updating
start_cache ( ) : void Start Cache
stop_cache ( ) : void Stop Cache
truncate ( $table = '' ) : object Truncate
update ( $table = '', $set = NULL, $where = NULL, $limit = NULL ) : object Update
update_batch ( $table = '', $set = NULL, $index = NULL ) : object Update_Batch
where ( $key, $value = NULL, $escape = TRUE ) : object Where
where_in ( $key = NULL, $values = NULL ) : object Where_in
where_not_in ( $key = NULL, $values = NULL ) : object Where_not_in

Method Details

_compile_select() public method

Generates a query string based on which functions were used. Should not be called directly. The get() function calls it.
public _compile_select ( $select_override = FALSE ) : string
return string

_create_alias_from_table() public method

Determines the alias name based on the table
public _create_alias_from_table ( $item ) : string
return string

_having() public method

Called by having() or or_having()
public _having ( $key, $value = '', $type = 'AND ', $escape = TRUE ) : object
return object

_like() public method

Called by like() or orlike()
public _like ( $field, $match = '', $type = 'AND ', $side = 'both', $not = '' ) : object
return object

_max_min_avg_sum() public method

select_max() select_min() select_avg() select_sum()
public _max_min_avg_sum ( $select = '', $alias = '', $type = 'MAX' ) : object
return object

_merge_cache() public method

When called, this function merges any cached AR arrays with locally called ones.
public _merge_cache ( ) : void
return void

_object_to_array() public method

Takes an object as input and converts the class variables to array key/vals
public _object_to_array ( $object ) : array
return array

_object_to_array_batch() public method

Takes an object as input and converts the class variables to array key/vals
public _object_to_array_batch ( $object ) : array
return array

_reset_run() public method

Resets the active record values. Called by the get() function
public _reset_run ( $ar_reset_items ) : void
return void

_reset_select() public method

Resets the active record values. Called by the get() function
public _reset_select ( ) : void
return void

_reset_write() public method

Called by the insert() update() and delete() functions
public _reset_write ( ) : void
return void

_track_aliases() public method

Used to track SQL statements written with aliased tables.
public _track_aliases ( $table ) : string
return string

_where() public method

Called by where() or orwhere()
public _where ( $key, $value = NULL, $type = 'AND ', $escape = NULL ) : object
return object

_where_in() public method

Called by where_in, where_in_or, where_not_in, where_not_in_or
public _where_in ( $key = NULL, $values = NULL, $not = FALSE, $type = 'AND ' ) : object
return object

count_all_results() public method

Generates a platform-specific query string that counts all records returned by an Active Record query.
public count_all_results ( $table = '' ) : string
return string

dbprefix() public method

Prepends a database prefix if one exists in configuration
public dbprefix ( $table = '' ) : string
return string

delete() public method

Compiles a delete string and runs the query
public delete ( $table = '', $where = '', $limit = NULL, $reset_data = TRUE ) : object
return object

distinct() public method

Sets a flag which tells the query string compiler to add DISTINCT
public distinct ( $val = TRUE ) : object
return object

empty_table() public method

Compiles a delete string and runs "DELETE FROM table"
public empty_table ( $table = '' ) : object
return object

flush_cache() public method

Empties the AR cache
public flush_cache ( ) : void
return void

from() public method

Generates the FROM portion of the query
public from ( $from ) : object
return object

get() public method

Compiles the select statement based on the other functions called and runs the query
public get ( $table = '', $limit = null, $offset = null ) : object
return object

get_where() public method

Allows the where clause, limit and offset to be added directly
public get_where ( $table = '', $where = null, $limit = null, $offset = null ) : object
return object

getwhere() public method

getwhere() is an alias of get_where() this function is here for backwards compatibility, as getwhere() has been deprecated
public getwhere ( $table = '', $where = null, $limit = null, $offset = null )

group_by() public method

GROUP BY
public group_by ( $by ) : object
return object

groupby() public method

groupby() is an alias of group_by() this function is here for backwards compatibility, as groupby() has been deprecated
public groupby ( $by )

having() public method

Separates multiple calls with AND
public having ( $key, $value = '', $escape = TRUE ) : object
return object

insert() public method

Compiles an insert string and runs the query
public insert ( $table = '', $set = NULL ) : object
return object

insert_batch() public method

Compiles batch insert strings and runs the queries
public insert_batch ( $table = '', $set = NULL ) : object
return object

join() public method

Generates the JOIN portion of the query
public join ( $table, $cond, $type = '' ) : object
return object

like() public method

Generates a %LIKE% portion of the query. Separates multiple calls with AND
public like ( $field, $match = '', $side = 'both' ) : object
return object

limit() public method

Sets the LIMIT value
public limit ( $value, $offset = '' ) : object
return object

not_like() public method

Generates a NOT LIKE portion of the query. Separates multiple calls with AND
public not_like ( $field, $match = '', $side = 'both' ) : object
return object

offset() public method

Sets the OFFSET value
public offset ( $offset ) : object
return object

or_having() public method

Separates multiple calls with OR
public or_having ( $key, $value = '', $escape = TRUE ) : object
return object

or_like() public method

Generates a %LIKE% portion of the query. Separates multiple calls with OR
public or_like ( $field, $match = '', $side = 'both' ) : object
return object

or_not_like() public method

Generates a NOT LIKE portion of the query. Separates multiple calls with OR
public or_not_like ( $field, $match = '', $side = 'both' ) : object
return object

or_where() public method

Generates the WHERE portion of the query. Separates multiple calls with OR
public or_where ( $key, $value = NULL, $escape = TRUE ) : object
return object

or_where_in() public method

Generates a WHERE field IN ('item', 'item') SQL query joined with OR if appropriate
public or_where_in ( $key = NULL, $values = NULL ) : object
return object

or_where_not_in() public method

Generates a WHERE field NOT IN ('item', 'item') SQL query joined with OR if appropriate
public or_where_not_in ( $key = NULL, $values = NULL ) : object
return object

order_by() public method

Sets the ORDER BY value
public order_by ( $orderby, $direction = '' ) : object
return object

orderby() public method

orderby() is an alias of order_by() this function is here for backwards compatibility, as orderby() has been deprecated
public orderby ( $orderby, $direction = '' )

orhaving() public method

orhaving() is an alias of or_having() this function is here for backwards compatibility, as orhaving() has been deprecated
public orhaving ( $key, $value = '', $escape = TRUE )

orlike() public method

orlike() is an alias of or_like() this function is here for backwards compatibility, as orlike() has been deprecated
public orlike ( $field, $match = '', $side = 'both' )

orwhere() public method

orwhere() is an alias of or_where() this function is here for backwards compatibility, as orwhere() has been deprecated
public orwhere ( $key, $value = NULL, $escape = TRUE )

replace() public method

public replace ( $table = '', $set = NULL )

select() public method

Generates the SELECT portion of the query
public select ( $select = '*', $escape = NULL ) : object
return object

select_avg() public method

Generates a SELECT AVG(field) portion of a query
public select_avg ( $select = '', $alias = '' ) : object
return object

select_max() public method

Generates a SELECT MAX(field) portion of a query
public select_max ( $select = '', $alias = '' ) : object
return object

select_min() public method

Generates a SELECT MIN(field) portion of a query
public select_min ( $select = '', $alias = '' ) : object
return object

select_sum() public method

Generates a SELECT SUM(field) portion of a query
public select_sum ( $select = '', $alias = '' ) : object
return object

set() public method

The "set" function. Allows key/value pairs to be set for inserting or updating
public set ( $key, $value = '', $escape = TRUE ) : object
return object

set_insert_batch() public method

The "set_insert_batch" function. Allows key/value pairs to be set for batch inserts
public set_insert_batch ( $key, $value = '', $escape = TRUE ) : object
return object

set_update_batch() public method

The "set_update_batch" function. Allows key/value pairs to be set for batch updating
public set_update_batch ( $key, $index = '', $escape = TRUE ) : object
return object

start_cache() public method

Starts AR caching
public start_cache ( ) : void
return void

stop_cache() public method

Stops AR caching
public stop_cache ( ) : void
return void

truncate() public method

Compiles a truncate string and runs the query If the database does not support the truncate() command This function maps to "DELETE FROM table"
public truncate ( $table = '' ) : object
return object

update() public method

Compiles an update string and runs the query
public update ( $table = '', $set = NULL, $where = NULL, $limit = NULL ) : object
return object

update_batch() public method

Compiles an update string and runs the query
public update_batch ( $table = '', $set = NULL, $index = NULL ) : object
return object

where() public method

Generates the WHERE portion of the query. Separates multiple calls with AND
public where ( $key, $value = NULL, $escape = TRUE ) : object
return object

where_in() public method

Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate
public where_in ( $key = NULL, $values = NULL ) : object
return object

where_not_in() public method

Generates a WHERE field NOT IN ('item', 'item') SQL query joined with AND if appropriate
public where_not_in ( $key = NULL, $values = NULL ) : object
return object

Property Details

$ar_aliased_tables public_oe property

public $ar_aliased_tables

$ar_cache_exists public_oe property

public $ar_cache_exists

$ar_cache_from public_oe property

public $ar_cache_from

$ar_cache_groupby public_oe property

public $ar_cache_groupby

$ar_cache_having public_oe property

public $ar_cache_having

$ar_cache_join public_oe property

public $ar_cache_join

$ar_cache_like public_oe property

public $ar_cache_like

$ar_cache_orderby public_oe property

public $ar_cache_orderby

$ar_cache_select public_oe property

public $ar_cache_select

$ar_cache_set public_oe property

public $ar_cache_set

$ar_cache_where public_oe property

public $ar_cache_where

$ar_caching public_oe property

Active Record Caching variables
public $ar_caching

$ar_distinct public_oe property

public $ar_distinct

$ar_from public_oe property

public $ar_from

$ar_groupby public_oe property

public $ar_groupby

$ar_having public_oe property

public $ar_having

$ar_join public_oe property

public $ar_join

$ar_like public_oe property

public $ar_like

$ar_limit public_oe property

public $ar_limit

$ar_offset public_oe property

public $ar_offset

$ar_order public_oe property

public $ar_order

$ar_orderby public_oe property

public $ar_orderby

$ar_select public_oe property

public $ar_select

$ar_set public_oe property

public $ar_set

$ar_store_array public_oe property

public $ar_store_array

$ar_where public_oe property

public $ar_where

$ar_wherein public_oe property

public $ar_wherein