The criteria category in Yii

Source: Internet
Author: User

$criteria = new Cdbcriteria;
Select
$criteria->select = ' * ';//default *
$criteria->select = ' id,name ';//field specified
$criteria->select = ' t.*,t.id,t.name ';//connection query, the first table as T, so with t.*
$criteria->distinct = FALSE; Whether the unique query


Join
$criteria->join = ' left join table2 T2 on (T.id=t2.tid) '; Connection table
$criteria->with = ' xxx '; Call relations


Where to query numeric fields
$criteria->addcondition ("id=1"); Query criteria, where id = 1
$criteria->addbetweencondition (' id ', 1, 4);//between 1 and 4
$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));//with the above exact phase, is not in


where query string field
$criteria->addsearchcondition (' name ', ' category ');//search conditions, in fact, represents the. Where name like '% category% '

Where Query Date field
$criteria->addcondition ("create_time> ' 2012-11-29 00:00:00");
$criteria->addcondition ("create_time< ' 2012-11-30 00:00:00");


where and OR
$criteria->addcondition (' id=1 ', ' or ');//This is an OR condition, when multiple conditions are, the condition is or rather than the and


This method is very special, and he will automatically process it into addcondition or addincondition according to your parameters.
That is, if the second argument is an array, the addincondition is called.


$criteria->compare (' id ', 1);
/** * Pass Parameters */


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


Order
$criteria->order = ' xxx desc,xxx ASC ';//Sort condition


Group
$criteria->group = ' group condition ';
$criteria->having = ' having condition ';


Limit
$criteria->limit = 10; Take 1 data, if less than 0, do not process
$criteria->offset = 1; Two is combined, which means that the limit is offset 1, or the representative. Limit 1,10

Criteria class in Yii

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.