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