How To Bind Array Param In Dao For In Clause

Hi I have a sql statement but not sure how to bind it properly.

//$id = Array


    [0] => 1

    [1] => 2

    [2] => 3


$sql = 'SELECT name FROM user WHERE id IN(1,2,3)';

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

$result = $cmd->query();

How would I remove hardcoded (1,2,3) and replace it with and bind my own array $id (structure shown above)?

Thanks :slight_smile:

Try this…

 $sql = Users::model()->find("FIND_IN_SET ($id,id)");


$sql = Users::model()->find("IN($id)");

Thanks, I should have added it’s a complex sql query, so AR is probably out of the question.