Home  >  Article  >  Backend Development  >  CDbCriteria detailed instructions

CDbCriteria detailed instructions

WBOY
WBOYOriginal
2016-08-08 09:24:331361browse

CDbCriteria
represents a standard query, such as conditions, order by and limit.
It is a data encapsulation object, equivalent to the carrier of each part of the SQL statement
CDbCriteria Public properties:
CDbCriteria.alias

string Type table alias.
CDbCriteria.condition string Type query condition
CDbCriteria.distinct boolean Whether type only selects different data rows
CDbCriteria.group string How to group query results by
CDbCriteria.having string type as the condition of GROUP-BY clause
CDbCriteria.index string type as query result array Index
CDbCriteria.join string How to join other tables
CDbCriteria.limit integer type to return the maximum record value
CDbCriteria.offset integer type to return the offset starting from 0
CDbCrite ria .order   string   类型如何对结果进行排序
CDbCriteria.paramCount  integer 类型绑定域名的全局记数器
CDbCriteria.param   array   类型以参数占位符为索引的Query parameter list
CDbCriteria.scopes mixed type defines multiple query conditions, combined
CDbCriteria.select mixed type selected column
CDbCriteria.with mixed Type-associated query criteria
CDbCriteria.addBetweenCondition() Add a between condition to the condition attribute
CDbCriteria.addColumnCondition() Append a condition that matches column values ​​
CDbCriteria.addCondition() Append a condition to an existing condition
------------------------------------------------ -----------------------------

Yii's Active Recorder packs a lot.

Especially include common phrases such as where, order, limit, IN/not IN, like in SQL into the CDbCriteria class, so that the entire code will be more standardized and clear at a glance.

$criteria =newCDbCriteria;


$criteria->addCondition("id=1"); //Query conditions, i.e. where id =1
$criteria->addInCondition('id', array(1,2,3,4 ,5));//Represents where id IN (1,23,,4,5,);
$criteria->addNotInCondition('id',array(1,2,3,4,5)) ;//Exactly the same as the above, it is NOT IN
$criteria->addCondition('id=1','OR');//This is an OR condition. When there are multiple conditions, the condition is OR Instead of AND
$criteria->addSearchCondition('name','category');//Search conditions actually represent. . where name like '%category%'
$criteria->addBetweenCondition('id', 1, 4);//between1 and 4

$criteria->compare('id',1); //This method is quite special. It will automatically process it into addCondition or addInCondition according to your parameters.
                                Condition("id = :id");

$criteria->params[':id']=1;
$criteria->select = 'id,parentid,name';//Represents the query Field, default select='*';

$criteria->join = 'xxx'; //Join table
$criteria->with = 'xxx';//Call relations
$criteria ->limit =10; //Take 1 piece of data. If it is less than 0, no processing will be done.
$criteria->offset =1; //When the two are combined, it means limit 10 offset1, or it represents. limit 1,10
$criteria->order = 'xxx DESC,XXX ASC' ;//Sort conditions
$criteria->group = 'group criteria';
$criteria->having = 'having conditions';
$criteria->distinct = FALSE; // Is it a unique query?

The above introduces the detailed instructions of CDbCriteria, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn