$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