0

Currently I am Using this query

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

But the problem with this query is that I am using $exhibitorIdentity and $productRecords directly. I think that it is dangerous. So how can i bind these values?

1 Answer 1

2

Try this... for more 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();

EDIT to

 $presentRecords=  Yii::app()->db
    ->createCommand()
    ->select('productId')
    ->from('exhibitorproducts')
    ->where(array("and","exhibitorId=:exhibitorId", array("in", "productId", ":productId")), array(':exhibitorId'=>$exhibitorIdentity, ':productId' => $productRecords))
    ->queryColumn();
Sign up to request clarification or add additional context in comments.

2 Comments

I tried it but its giving the false result. for IN (2,3) its returning result for only 2 and if i remove 2 from the query then its showing result for 3 :(
$productRecords is an array(2,3) and so It throws error Array to string conversion for $productRecords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.