我正在使用Yii 1.1.15并尝试创建查询。但当我得到no parameters where bound error
这是我的代码如下。从doc看起来我正在做的一切正确。
$user = Yii::app()->db->createCommand()
->select()
->from('ABC')
->where('id=:id0 AND id=:id1 AND id=:id2', array(':id0'=> '07Q00G', ':id1'=>'07Q01A', ':id2'=>'07Q02A'))
->execute();
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. The SQL statement executed was: SELECT *
FROM `ABC`
WHERE id=:id0 AND id=:id1 AND id=:id2
当我使用->query()
代替->execute()
时,它就是回声。并没有取代变量
CDbDataReader Object ( [_statement:CDbDataReader:private] => PDOStatement Object ( [queryString] => SELECT * FROM `ABC` WHERE id=:id0 AND id=:id1 AND id=:id2 ) [_closed:CDbDataReader:private] => [_row:CDbDataReader:private] => [_index:CDbDataReader:private] => -1 [_e:CComponent:private] => [_m:CComponent:private] => )
知道我在这里缺少什么吗?
答案 0 :(得分:0)
而不是执行(),您应该queryAll()
所以它应该是
$user = Yii::app()->db->createCommand()
->select()
->from('ABC')
->where('id=:id0 AND id=:id1 AND id=:id2', array(':id0'=> '07Q00G', ':id1'=>'07Q01A', ':id2'=>'07Q02A'))
->queryAll();