system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CDbCriteria

system.db.schema
继承 class CDbCriteria
可用自 1.0
版本 $Id$
CDbCriteria represents a query criteria, such as conditions, ordering by, limit/offset.

公共属性

隐藏继承的属性

属性类型描述被定义在
condition string query condition. CDbCriteria
distinct boolean whether to select distinct rows of data only. CDbCriteria
group string how to group the query results. CDbCriteria
having string the condition to be applied with GROUP-BY clause. CDbCriteria
join string how to join with other tables. CDbCriteria
limit integer maximum number of records to be returned. CDbCriteria
offset integer zero-based offset from where the records are to be returned. CDbCriteria
order string how to sort the query results. CDbCriteria
params array list of query parameter values indexed by parameter placeholders. CDbCriteria
select mixed the columns being selected. CDbCriteria

公共方法

隐藏继承的方法

方法描述被定义在
__construct() Constructor. CDbCriteria
addColumnCondition() Appends a condition for matching the given list of column values. CDbCriteria
addCondition() Appends a condition to the existing condition. CDbCriteria
addInCondition() Appends an IN condition to the existing condition. CDbCriteria
addSearchCondition() Appends a search condition to the existing condition. CDbCriteria
mergeWith() Merges with another criteria. CDbCriteria
toArray() CDbCriteria

属性详情

condition 属性
public string $condition;

query condition. This refers to the WHERE clause in an SQL statement. For example, age>31 AND team=1.

distinct 属性 (自版本 v1.0.9 可用)
public boolean $distinct;

whether to select distinct rows of data only. If this is set true, the SELECT clause would be changed to SELECT DISTINCT.

group 属性
public string $group;

how to group the query results. This refers to the GROUP BY clause in an SQL statement. For example, 'projectID, teamID'.

having 属性 (自版本 v1.0.1 可用)
public string $having;

the condition to be applied with GROUP-BY clause. For example, 'SUM(revenue)<50000'.

join 属性
public string $join;

how to join with other tables. This refers to the JOIN clause in an SQL statement. For example, 'LEFT JOIN users ON users.id=authorID'.

limit 属性
public integer $limit;

maximum number of records to be returned. If less than 0, it means no limit.

offset 属性
public integer $offset;

zero-based offset from where the records are to be returned. If less than 0, it means starting from the beginning.

order 属性
public string $order;

how to sort the query results. This refers to the ORDER BY clause in an SQL statement.

params 属性
public array $params;

list of query parameter values indexed by parameter placeholders. For example, array(':name'=>'Dan', ':age'=>31).

select 属性
public mixed $select;

the columns being selected. This refers to the SELECT clause in an SQL statement. The property can be either a string (column names separated by commas) or an array of column names. Defaults to '*', meaning all columns.

方法详情

__construct() 方法
public void __construct(array $data=array ( ))
$data array criteria initial property values (indexed by property name)

Constructor.

addColumnCondition() 方法 (自版本 v1.0.10 可用)
public CDbCriteria addColumnCondition(array $columns, string $columnOperator='AND', string $operator='AND')
$columns array list of column names and values to be matched (name=>value)
$columnOperator string the operator to concatenate multiple column matching condition. Defaults to 'AND'.
$operator string the operator used to concatenate the new condition with the existing one. Defaults to 'AND'.
{return} CDbCriteria the criteria object itself

Appends a condition for matching the given list of column values. The generated condition will be concatenated to the existing condition via the specified operator which defaults to 'AND'. The condition is generated by matching each column and the corresponding value.

addCondition() 方法 (自版本 v1.0.9 可用)
public CDbCriteria addCondition(mixed $condition, string $operator='AND')
$condition mixed the new condition. It can be either a string or an array of strings.
$operator string the operator to join different conditions. Defaults to 'AND'.
{return} CDbCriteria the criteria object itself

Appends a condition to the existing condition. The new condition and the existing condition will be concatenated via the specified operator which defaults to 'AND'. The new condition can also be an array. In this case, all elements in the array will be concatenated together via the operator. This method handles the case when the existing condition is empty. After calling this method, the condition property will be modified.

addInCondition() 方法 (自版本 v1.0.10 可用)
public CDbCriteria addInCondition(string $column, array $values, string $operator='AND')
$column string the column name (or a valid SQL expression)
$values array list of values that the column value should be in
$operator string the operator used to concatenate the new condition with the existing one. Defaults to 'AND'.
{return} CDbCriteria the criteria object itself

Appends an IN condition to the existing condition. The IN condition and the existing condition will be concatenated via the specified operator which defaults to 'AND'. The IN condition is generated by using the SQL IN operator which requires the specified column value to be among the given list of values.

addSearchCondition() 方法 (自版本 v1.0.10 可用)
public CDbCriteria addSearchCondition(string $column, string $keyword, boolean $escape=true, string $operator='AND')
$column string the column name (or a valid SQL expression)
$keyword string the search keyword. This interpretation of the keyword is affected by the next parameter.
$escape boolean whether the keyword should be escaped if it contains characters % or _. When this parameter is true (default), the special characters % (matches 0 or more characters) and _ (matches a single character) will be escaped, and the keyword will be surrounded with a % character on both ends. When this parameter is false, the keyword will be directly used for matching without any change.
$operator string the operator used to concatenate the new condition with the existing one. Defaults to 'AND'.
{return} CDbCriteria the criteria object itself

Appends a search condition to the existing condition. The search condition and the existing condition will be concatenated via the specified operator which defaults to 'AND'. The search condition is generated using the SQL LIKE operator with the given column name and search keyword.

mergeWith() 方法 (自版本 v1.0.5 可用)
public void mergeWith(CDbCriteria $criteria, boolean $useAnd=true)
$criteria CDbCriteria the criteria to be merged with.
$useAnd boolean whether to use 'AND' to merge condition and having options. If false, 'OR' will be used instead. Defaults to 'AND'. This parameter has been available since version 1.0.6.

Merges with another criteria. In general, the merging makes the resulting criteria more restrictive. For example, if both criterias have conditions, they will be 'AND' together. Also, the criteria passed as the parameter takes precedence in case two options cannot be merged (e.g. LIMIT, OFFSET).

toArray() 方法 (自版本 v1.0.6 可用)
public array toArray()
{return} array the array representation of the criteria