UPDATE「無效參數號:沒有定義參數的」插入數據
我正在一個小錯誤列出值時,。我應該把「:用戶名」,而不是「:別名」。我想這個問題的答案是對任何需要它的人來說是免費的嗎?或者我刪除這個問題?
ORIGINAL
我一直在使用Yii的活動記錄圖形一會兒。現在,我的項目需要爲一個小事務訪問不同的數據庫。我認爲Yii的DAO對此會有好處。但是,我收到了一個神祕的錯誤。
CDbCommand未能執行SQL語句:SQLSTATE [HY093]:無效的參數號:沒有定義的參數
這裏是我的代碼:
public function actionConfirmation
{
$model_person = new TempPerson();
$model = $model_person->find('alias=:alias',array(':alias'=>$_GET['alias']));
$connection=Yii::app()->db2;
$sql = "INSERT INTO users (username, password, ssn, surname
, firstname, email, city, country)
VALUES(:alias, :password, :ssn, :surname
, :firstname, :email, :city, :country)";
$command=$connection->createCommand($sql);
$command->bindValue(":username", $model->alias);
$command->bindValue(":password", substr($model->ssn, -4,4));
$command->bindValue(":ssn", $model->ssn);
$command->bindValue(":surname", $model->lastName);
$command->bindValue(":firstname", $model->firstName);
$command->bindValue(":email", $model->email);
$command->bindValue(":city", $model->placeOfBirth);
$command->bindValue(":country", $model->placeOfBirth);
$command->execute();
$this->render('confirmation',array('model'=>$model));
}
此構造下面的查詢(如在應用日誌中所見):
INSERT INTO users (username, password, ssn, surname, firstname, email
, city, country)
VALUES(:alias, :password, :ssn, :surname, :firstname, :email, :city, :country);
FYI $model->placeOfBirth
應該是城市和縣的價值。這不是一個錯字(只是我必須做的一件愚蠢的事情)。
好帖子。我發現在我的實例中,我在col列名之後有一個空格,並且足以引發錯誤。 – salonMonsters 2011-12-19 23:52:46
我的問題是':參數'名稱中的變音符號... – testing 2012-08-31 13:37:12
這裏有效的佔位符字符列表http://stackoverflow.com/questions/5809951/pdo-valid-characters-for-placeholders – maartenmachiels 2013-07-08 12:04:39