目前我正在使用此查询
$presentRecords= Yii::app()->db
->createCommand()
->select('productId')
->from('exhibitorproducts')
->where(array('and',"exhibitorId=$exhibitorIdentity",
array('in','productId',$productRecords)))
->queryColumn();
但是这个问题的问题在于我直接使用 $ exhibitorIdentity 和 $ productRecords 。我认为这很危险。 那么如何绑定这些值?
答案 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();