Yii addInCondition

旧街凉风 提交于 2019-12-23 17:54:27

问题


I've tried to get rows from table according to my conditions. My code:

$conditions = array(
  'id' => array ('148028','118508')
);

$criteria = new CDbCriteria();
foreach($conditions as $key => $values){
  $criteria->addInCondition($key, $values);
}
if(!is_null($limit)) $criteria->limit = $limit;

$rows = Item::model()->findAll($criteria);

These rows exist,but result is empty. Binding params exist in criteria object.

Log looks like:

system.db.CDbCommand.query(SELECT * FROM `items` `t` WHERE id IN (:ycp0, :ycp1) LIMIT 2)

i think, that params in criteria dont bind to a query.

Is my code right?


回答1:


Try follow this

$criteria->addInCondition('id', array ('148028','118508'));



回答2:


Try this,
$criteria->addInCondition($key, $values,'OR');

where $key - field name, $values - array of parametrs



来源:https://stackoverflow.com/questions/13564221/yii-addincondition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!