在我的Yii應用,我有一個表示siteconfig
表的模型,並有四列:ActiveRecord的搜索返回「語法錯誤或訪問衝突」錯誤
- 整數
config_id
, - 串
key
, - 字符串
value
, - 字符串
update_time
。
我使用Gii創建了一個模型(以確保我不會犯任何錯誤)。我不會在這裏發佈整個代碼,因爲這是我修改的100%,由Gii生成的標準模型代碼。由於我的問題是有關搜索,我只發佈的生成代碼(search()
法)重要組成部分:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('config_id',$this->config_id);
$criteria->compare('key',$this->key,true);
$criteria->compare('value',$this->value,true);
$criteria->compare('update_time',$this->update_time,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
我試圖使用生成的模型在正常的Yii ActiveRecord的搜索這樣的:
$etona = new SiteConfigurationRecord();
$crit = new CDbCriteria();
$crit->select = "value";
$crit->condition = "key=:key";
$crit->params = array(":key"=>"sitename");
$etona = $etona->find($crit);
但是,不但得不到預期的搜索結果,發生了奇怪的(對我來說)錯誤:
CDbCommand未能執行SQL語句:SQLSTATE [42000]: 語法錯誤或訪問衝突:1064 SQL 語法中有錯誤;請檢查與您的MySQL服務器版本 對應的手冊,以獲取在第1行'key ='sitename'LIMIT 1'附近使用的正確語法。 執行的SQL語句爲:SELECT value FROM
siteconfig
t
WHERE key =:key LIMIT 1
我哪裏出錯了?