ActiveRecord使用的一个陷阱导致 Invalid parameter number: no parameters were bound
请看下面的例子
$criteria = new CDbCriteria();
$criteria->select = "*";
$model = Biubiu::model();
$ids = range(160,163);
$criteria->addInCondition("id", $ids);
$model->findByPk(160);//某次操作
sleep(32);//处理其他事情花费了较长时间。
$result = $model->findAll($criteria);<1>
//$result = $model->getCommandBuilder()->createFindCommand($model->getTableSchema(),$criteria)->queryAll();<2>
if($result){
echo count($result);
}
为了体现这个问题,我的本地数据库wait_timeout = 30
那么会出现下面的问题:
exception 'Exception' with message 'exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. The SQL statement executed was: SELECT * FROM `t_biubiu` `t` WHERE id IN (:ycp0, :ycp1, :ycp2, :ycp3). Bound with :ycp0=160, :ycp1=161, :ycp2=162, :ycp3=163' in E:\xxxx\framework\db\CDbCommand.php:569
Stack trace:
#0 E:\xx