Home >Backend Development >PHP Tutorial >Summary of commonly used CDbCriteria in Yii, yiicdbcriteria_PHP tutorial

Summary of commonly used CDbCriteria in Yii, yiicdbcriteria_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:17:37864browse

Common summary of CDbCriteria in Yii, yiicdbcriteria

Reprinted from: http://www.cnblogs.com/mrcoke/articles/Yii.html

Yii’s Active Recorder comes packed with a lot.

In particular, include common phrases such as where, order, limit, IN/not IN, like, etc. 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, that is, 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 The condition is OR instead of AND
$criteria->addSearchCondition('name','category');//The search conditions actually represent. . where name like '%category%'
$criteria->addBetweenCondition('id', 1, 4);//between1 and 4

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

$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; //Take 1 piece of data, if it is less than 0, do not process it
$criteria->offset =1; //Combined two pieces of data, it means limit 10 offset1, or represents. limit 1,10
$criteria->order = 'xxx DESC,XXX ASC' ;//Sort conditions
$criteria->group = 'group condition';
$criteria->having = 'having conditions';
$criteria->distinct = FALSE; // Is it a unique query


How can the data extracted from yii be introduced to some data that they need to extract sometimes, and care about others

You can use the CDbCriteria class in find to perform various SQL operations. Please refer to the documentation for specific usage.
blog.csdn.net/...973922 This place also has many explanations of database-related operations, which are very detailed and comprehensive.


If you only need to select specific fields, you can use the following method
model()->find(array('select' => 'Field name 1, field name 2', 'condition ' => 'Selection condition'))
findAll is similar



Yii CDbCriteria supports stored procedures

I don’t know what your needs are, why do you have to use ready-made components? Try it,
$sql = "call fun()";
$data = Yii::app()- >db->createCommand($sql)->queryAll();




http://www.bkjia.com/PHPjc/891594.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/891594.htmlTechArticleCommon summary of CDbCriteria in Yii, yiicdbcriteria Reprinted from: http://www.cnblogs.com/mrcoke/articles/Yii .html Yii's Active Recorder wraps up a lot. Especially put where, order, l... in SQL
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