Findall - Invalid Parameter Number. But Worked Before.

Code:


$criteria = new CDbCriteria;

$criteria->condition='id=:jednotka_id OR jednotka_id=:jednotka_id';

$criteria->params=array(':jednotka_id'=>$jednotka_id);


Jednotka::model()->findAll($criteria);

Application log:

CDbCommand::fetchAll() failed: SQLSTATE[HY093]: Invalid parameter number. The SQL statement executed was: SELECT * FROM jednotka t WHERE id=:jednotka_id OR jednotka_id=:jednotka_id. Bound with :jednotka_id=6101601.

Workaround:

Jednotka::model()->findAll(‘id=’.$jednotka_id.’ OR jednotka_id=’.$jednotka_id);

Any idea why first code stop working?

Thanks

Marek

i had similar issue, somehow you could not re-use parameter in this case, try


$criteria->condition='id=:jednotka_id1 OR jednotka_id=:jednotka_id2';

$criteria->params=array(':jednotka_id1'=>$jednotka_id1, ':jednotka_id2'=>$jednotka_id2);



Thanks for the answer. Your code works.

However it does not explain why the code stopped working. Worked over half a year. I made some changes on project today, but only minor changes - not core files.

It looks like stop working when I turn off emulatePrepare in my config.