$criteria = new CDbCriteria; //select $criteria->select = '*';//默認* $criteria->select = 'id,name';//指定的字段 $criteria->select = 't.*,t.id,t.name';//鏈接查詢時,第一個表as t,因此用t.* $criteria->distinct = FALSE; //是否惟一查詢 //join $criteria->join = 'left join table2 t2 on(t.id=t2.tid)'; //鏈接表 $criteria->with = 'xxx'; //調用relations //where 查詢數字字段 $criteria->addCondition("id=1"); //查詢條件,即where id = 1 $criteria->addBetweenCondition('id', 1, 4);//between 1 and 4 $criteria->addInCondition('id', array(1,2,3,4,5)); //表明where id IN (1,23,,4,5,); $criteria->addNotInCondition('id', array(1,2,3,4,5));//與上面正好相法,是NOT IN //where 查詢字符串字段 $criteria->addSearchCondition('name', '分類');//搜索條件,其實表明了。。where name like '%分類%' //where 查詢日期字段 $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');//這是OR條件,多個條件的時候,該條件是OR而非AND //這個方法比較特殊,他會根據你的參數自動處理成addCondition或者addInCondition, //即若是第二個參數是數組就會調用addInCondition $criteria->compare('id', 1); /** * 傳遞參數 */ $criteria->addCondition("id = :id"); $criteria->params[':id']=1; //order $criteria->order = 'xxx DESC,XXX ASC' ;//排序條件 //group $criteria->group = 'group 條件'; $criteria->having = 'having 條件 '; //limit $criteria->limit = 10; //取1條數據,若是小於0,則不做處理 $criteria->offset = 1; //兩條合併起來,則表示 limit 10 offset 1,或者表明了。limit 1,10