Yii In Query中的绑定值

时间:2013-12-27 10:02:47

标签: php yii

目前我正在使用此查询

$presentRecords=  Yii::app()->db
->createCommand()
->select('productId')
->from('exhibitorproducts')
->where(array('and',"exhibitorId=$exhibitorIdentity",
array('in','productId',$productRecords)))
->queryColumn();

但是这个问题的问题在于我直接使用 $ exhibitorIdentity $ productRecords 。我认为这很危险。 那么如何绑定这些值?

1 个答案:

答案 0 :(得分:2)

试试这个...... 更多http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder

$presentRecords=  Yii::app()->db
->createCommand()
->select('productId')
->from('exhibitorproducts')
->where("exhibitorId=:exhibitorId AND productId IN (:productId)", array(':exhibitorId'=>$exhibitorIdentity, ':productId' => $productRecords))
->queryColumn();

编辑到

 $presentRecords=  Yii::app()->db
    ->createCommand()
    ->select('productId')
    ->from('exhibitorproducts')
    ->where(array("and","exhibitorId=:exhibitorId", array("in", "productId", ":productId")), array(':exhibitorId'=>$exhibitorIdentity, ':productId' => $productRecords))
    ->queryColumn();
相关问题