“參數(shù)號(hào)無效:未定義參數(shù)”插入數(shù)據(jù)UPDATE列出VALUES時(shí)我犯了一個(gè)小錯(cuò)誤。我應(yīng)該輸入“:username”而不是“:alias”。我想這個(gè)問題的答案可歸功于任何想要它的人的自由統(tǒng)治嗎?或者我刪除這個(gè)問題?原版的我一直在使用Yii的活躍記錄模式?,F(xiàn)在,我的項(xiàng)目需要為一個(gè)小事務(wù)訪問不同的數(shù)據(jù)庫。我認(rèn)為Yii的DAO對(duì)此有好處。但是,我收到了一個(gè)神秘的錯(cuò)誤。CDbCommand無法執(zhí)行SQL語句:SQLSTATE [HY093]:參數(shù)號(hào)無效:未定義參數(shù)這是我的代碼: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));}這構(gòu)造了以下查詢(如應(yīng)用程序日志中所示):INSERT INTO users (username, password, ssn, surname, firstname, email , city, country) VALUES(:alias, :password, :ssn, :surname, :firstname, :email, :city, :country);FYI $model->placeOfBirth應(yīng)該是城市和縣的價(jià)值觀。這不是一個(gè)錯(cuò)字(我只是一件傻事)。
3 回答

GCT1015
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
上面沒有提到的這個(gè)錯(cuò)誤的原因是當(dāng)你處理一個(gè)動(dòng)態(tài)的參數(shù)數(shù)組時(shí),如果你取消設(shè)置任何參數(shù),你需要在傳入它們之前重新索引。這個(gè)的殘酷部分是你的錯(cuò)誤日志沒有顯示索引,看起來一切都是正確的。例如:
SELECT id WHERE x = ?, y = ?, z = ?
可能產(chǎn)生Log:無效的參數(shù)號(hào):參數(shù)未定義為params(“x”,“y”,“z”)
這看起來不應(yīng)該拋出錯(cuò)誤,但如果索引是這樣的:
0 => x, 1 => y, 4 => z
它認(rèn)為最后一個(gè)參數(shù)未定義,因?yàn)樗趯ふ益I2。

DIEA
TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊
可能是你試圖用單引號(hào)綁定一個(gè)參數(shù)而不是讓它為你工作。
相比:
Model::model()->findAll("t.description ilike '%:filter%'", array(':filter' => $filter));
附:
Model::model()->findAll("t.description ilike :filter", array(':filter' => '%' . $filter . '%'));
- 3 回答
- 0 關(guān)注
- 962 瀏覽
添加回答
舉報(bào)
0/150
提交
取消