I've been using Yii's active record pattern for a while. Now, my project needs to access a different database for one small transaction. I thought the Yii's DAO would be good for this. However, I'm getting a cryptic error.
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Here is my code:
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)); } This constructs the following query (as seen on the application log):
INSERT INTO users (username, password, ssn, surname, firstname, email , city, country) VALUES(:alias, :password, :ssn, :surname, :firstname, :email, :city, :country); FYI $model->placeOfBirth is supposed to be in both city and county values. That's not a typo (just a silly thing I have to do).