How to bind array parameters in Yii framework?

Cherry picture Cherry · Mar 2, 2012 · Viewed 22k times · Source

I have below code:

$inputs = "1,2,3,4,5";
$sql = "SELECT * FROM obj WHERE id IN(:input)";

$commond = Yii::app()->db->createCommand($sql);
$commond->bindValue(":input", $inputs , PDO::PARAM_STR);

But the query result is incorrect. How to bind params for such IN condition?

Answer

Uday Sawant picture Uday Sawant · Mar 2, 2012

for now use it like this

$command = Yii::app()->db->createCommand()
    ->select()
    ->from('tableName')
    ->where(array('in', 'id', explode(',', $inputs)));

I ll try to get back with $command->bindValue() method.