I’m trying to perform a search in one of my tables based on a given criteria like so:

$id = 1;

$criteria = new CDbCriteria();


$currencies = User::model()->findAll($criteria, array(':currency' => $id,)); 		

I get a CDbException:

CDbCommand failed to execute the SQL statement: 

SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. 

The SQL statement executed was: 

	SELECT * FROM `user` `t` 

	WHERE usr_currency=:currency

Where as, this works:

$id = 1;

$criteria = new CDbCriteria();


$criteria->params = array(':currency' => $id,);

$comments = User::model()->findAll($criteria); 		

What is wrong with the first code fragment?

You answer yourself, the correct answer is the second code.

Second argument ($params) is used only when the first argument ($criteria) is a string.

For example, this should work:

$currencies = User::model()->findAll('usr_currency=:currency', array(':currency' => $id,));