UPDATE
列出VALUES时我犯了一个小错误.我应该输入“:username”而不是“:alias”.我想这个问题的答案可归功于任何想要它的人的自由统治吗?或者我删除这个问题?
原版的
我一直在使用Yii的活跃记录模式.现在,我的项目需要为一个小事务访问不同的数据库.我认为Yii的DAO对此有好处.但是,我收到了一个神秘的错误.
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
这是我的代码:
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应该是城市和县值.这不是一个错字(我只是一件傻事).