CDbCriteria detailed instructions

Source: Internet
Author: User
: This article describes CDbCriteria in detail. if you are interested in the PHP Tutorial, refer to it. CDbCriteria
Represents a standard query, such as a condition, order by, and limit.
It is a data encapsulation object, which is equivalent to the carrier of each part of the SQL statement.
CDbCriteria public attributes:
CDbCriteria. alias

String Type Table alias.
CDbCriteria. condition String Type query conditions
CDbCriteria. distinct Boolean Whether to select different data rows for different types
CDbCriteria. group String Type: How to query results by group
CDbCriteria. having String Type as a condition for the GROUP-BY clause
CDbCriteria. index String Index of the query result array
CDbCriteria. join StringHow to add types to other tables
CDbCriteria. limit The maximum record value to be returned for the integer type.
CDbCriteria. offset The integer type returns the offset starting from 0.
CDbCriteria. order String How to sort results by type
CDbCriteria. paramCountGlobal stenographer bound to a domain name of the integer type
CDbCriteria. param Array List of query parameters indexed by parameter placeholders
CDbCriteria. scopes Mixed Type defines multiple query conditions for combination
CDbCriteria. select Mixed Type selected column
CDbCriteria. Mixed Type-related query criteria
CDbCriteria. addBetweenCondition ()Add a between condition to the condition attribute.
CDbCriteria. addColumnCondition () conditions for attaching a matched column value
CDbCriteria. addCondition () attaches a condition to an existing condition.
---------------------------------------------------------------------------

Yii's Active Recorder is packed a lot.

IN particular, common SQL statements such as where, order, limit, IN/not IN, and like are included IN the CDbCriteria class, so that the entire code is more standardized and clear at a glance.

$ Criteria = newCDbCriteria;


$ Criteria-> addCondition ("id = 1"); // query condition, that is, where id = 1
$ Criteria-> addInCondition ('id', array (, 5); // represents where id IN ,);
$ Criteria-> addNotInCondition ('id', array (, 5); // it is IN the same phase as above, NOT IN
$ Criteria-> addCondition ('Id = 1', 'OR'); // This is an OR condition. when multiple conditions exist, the condition is OR rather than AND.
$ Criteria-> addSearchCondition ('name', 'category'); // The search condition actually represents .. Where name like '% Category %'
$ Criteria-> addBetweenCondition ('id', 1, 4); // between1 and 4

$ Criteria-> compare ('id', 1); // This method is special and will be automatically processed as addCondition or addInCondition according to your parameters,
// If the second parameter is an array, addInCondition is called.

$ Criteria-> addCondition ("id =: id ");
$ Criteria-> params [': id'] = 1;

$ Criteria-> select = 'id, parentid, name'; // indicates the field to be queried. the default value is select = '*';
$ Criteria-> join = 'XXX'; // connection table
$ Criteria-> with = 'XXX'; // call relations
$ Criteria-> limit = 10; // Obtain 1 piece of data. if the value is smaller than 0, no processing is performed.
$ Criteria-> offset = 1; // when the two parameters are merged, the limit 10 offset1 is used or the limit 10 offset1 is used. Limit 1, 10
$ Criteria-> order = 'XXX DESC, xxx ASC '; // sorting condition
$ Criteria-> group = 'group condition ';
$ Criteria-> having = 'having condition ';
$ Criteria-> distinct = FALSE; // whether the query is unique


The above describes CDbCriteria in detail, including some content. I hope my friends who are interested in the PHP Tutorial can help me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.