Yii CDbCriteria常用总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/eddy23513/article/details/80340209

https://blog.csdn.net/u012322925/article/details/48245861

https://www.yiichina.com/doc/api/1.1/CDbCriteria
1、条件查询

$criteria = new CDbCriteria;
$criteria->order = 'user_name';
$criteria->addInCondition('id',$permissions);
$criteria->addInCondition('user_name',$permissions,'OR');
$accountModels = (new Ebay())->findAll($criteria);
$criteria =new CDbCriteria; 

$criteria->distinct = FALSE;                   //是否唯一查询

$criteria->addCondition("id=1"); //查询条件,即where id =1  
$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  

$criteria->addCondition('id=1','OR');//这是OR条件,多个条件的时候,该条件是OR而非AND 

$criteria->addSearchCondition('name','分类');//搜索条件,其实代表了。。where name like '%分类%'  

$criteria->addBetweenCondition('id', 1, 4);//between1 and 4   

运行查询:

This property is effective only when passing criteria to the one of the following methods:
CActiveRecord::find()
CActiveRecord::findAll()
CActiveRecord::findByPk()
CActiveRecord::findAllByPk()
CActiveRecord::findByAttributes()
CActiveRecord::findAllByAttributes()
CActiveRecord::count()
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页