This article mainly introduces the usage of CDbCriteria query conditions in Yii. The example summarizes the common usage of CDbCriteria query conditions, which has some reference value for database program design using Yii, for more information about Yii CDbCriteria, see the examples in this article. The specific analysis is as follows:
Here are the various conditions for using the CDbCriteria method to query in Yii:
The code is as follows:
$ Criteria = new CDbCriteria;
$ Criteria-> addCondition ("MACID = 464"); // 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 ('link', 'noise'); // search criteria where name like '% Category %'
$ Criteria-> addBetweenCondition ('id', 10000,100 05); // between 10000 and 10005
$ Criteria-> compare ('id', 1); // This method is special and will be based on your parameters
// It is automatically processed as addCondition or addInCondition,
// If the second parameter is an array, addInCondition is called.
/**
* Passing variables
*/
$ Criteria-> addCondition ("id =: id ");
$ Criteria-> params [': id'] = 10;
/**
* Some public vars
*/
$ Criteria-> select = 'id, MACID, type'; // 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; // if the two parameters are merged, the limit 10 offset 1 is used, or the limit 10 offset 1 is used. Limit 1, 10
$ Criteria-> order = 'Id DESC, macid asc '; // sorting condition
$ Criteria-> group = 'group type ';
$ Criteria-> having = 'having condition ';
$ Criteria-> distinct = FALSE; // whether the query is unique
Return new CActiveDataProvider ('visitlog', array (
'Criteria '=> $ criteria,
));
I hope this article will help you design PHP programs based on the Yii Framework.