How do I bind an array to an IN condition with findAllBySql() ?


Is there a way to bind an array to a placeholder parameter in a "IN" condition of a SQL query the same way as you bind other types?

For example, this works:


$sql="SELECT * FROM sometable WHERE someattr=:value";


$somemodel->findAllBySql($sql, $params);

However, this won’t work:

$values=array('foo', 'bar', 'boo');

$sql="SELECT * FROM sometable WHERE someattr IN (:values)";


$somemodel->findAllBySql($sql, $params);

How do I do that?

Or is it impossible at all to bind an array to a prepared statement?

I know I can do

 $sql="SELECT * FROM sometable WHERE someattr IN (".implode(',',$values).")";

and forget the $params, but I’m looking for the elegant way.




I dont think it is possible to work with $params as array by using findAllBySql method

but as alternative you can use addInCondition method by using CDbCriteria as demontred

in documentation example


In your case it will be

                $values=array('foo', 'bar', 'boo'); 

                $criteria=new CDbCriteria; 



Hope it will be helpfull.