Home > Backend Development > PHP Tutorial > Summary of common methods of Yii CDbCriteria_PHP tutorial

Summary of common methods of Yii CDbCriteria_PHP tutorial

WBOY
Release: 2016-07-12 09:07:52
Original
797 people have browsed it

Summary of common methods of Yii CDbCriteria

Summary of common methods of Yii CDbCriteria.

$criteria = new CDbCriteria;

$criteria->addCondition("id=1"); //Query conditions, that is, where id = 1
$criteria->addInCondition('id', array(1,2,3,4,5)); //Represents where id IN (1,2,3,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);//between 1 and 4
$criteria->compare('id', 1); //This method is quite special, it will automatically process it into addCondition or addInCondition according to your parameters,
//That is, if the second parameter is an array, addInCondition will be called

/**
* Pass variables
​*/
$criteria->addCondition("id = :id");
$criteria->params[':id']=1;

/**
* Some public vars
​*/

$criteria->select = 'id,parentid,name'; //Represents the field to be queried, the default select='*';
$criteria->join = 'xxx'; //Join table
$criteria->with = 'xxx'; //Call relations
$criteria->limit = 10; //Get 1 piece of data, if it is less than 0, it will not be processed
$criteria->offset = 1; //When the two are combined, it means limit 10 offset 1, or it represents. limit 1,10
$criteria->order = 'xxx DESC,XXX ASC' ;//Sort conditions
$criteria->group = 'group criteria';
$criteria->having = 'having criteria';
$criteria->distinct = FALSE; // Is the query unique

Multiple table query

$criteria=new CDbCriteria;
$criteria->alias = 'Invoice';
$criteria->join='LEFT JOIN Client ON Client.id=Invoice.clientId';
$criteria->condition='Client.businessId='. Yii::app()->userInfo->business;

Articles you may be interested in

  • Yii rules common validation rules memo
  • Summary of common path methods in Yii
  • How to configure the default controller and action in the yii framework
  • Safe usage of validator in Yii
  • Summary of how to use database transactions in Yii
  • Understanding of Yii framework Yiiapp()
  • Yii implementation method of using find findAll to find out specified fields
  • Summary of yii rules verification examples

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1058852.htmlTechArticle Summary of common methods of Yii CDbCriteria Summary of common methods of Yii CDbCriteria. $criteria = new CDbCriteria; $criteria-addCondition("id=1"); //Query conditions, that is, where id = 1 $criteria...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template