Use 'in' Condition With Cdbcommand

I’m doing simple database query, but i can’t found a properly way about how should be used ‘IN’ condition with bindParam(),

I could think it’s so easy like this

$sql="select * from user where firstname in :name";

$command= Yii::app()->db->createCommand($sql);

$command->bindParam(":name", $foo, PDO::PARAM_STR);



Try to use CDbCommandBuilder::createFindCommand() and CDbCriteria::addInCondition(). You can pass IN-values in $values param using CDbCriteria:

$builder = Yii::app()->db->schema->commandBuilder;

// your IN-array        

$foo = array(1, 2, 3);

$cr = new CDbCriteria();

$cr->addInCondition('id', $foo);


$command = $builder->createFindCommand('user', $cr);