php - "Invalid parameter number: parameter was not defined" Inserting data -


update

i making petty mistake when listing values. should have put ":username" , not ":alias". suppose answer credit question free reign wants it? or delete question?

original

i've been using yii's active record pattern while. now, project needs access different database 1 small transaction. thought yii's dao this. however, i'm getting cryptic error.

cdbcommand failed execute sql statement: sqlstate[hy093]: invalid parameter number: parameter not defined

here code:

public function actionconfirmation {     $model_person = new tempperson();      $model = $model_person->find('alias=:alias',array(':alias'=>$_get['alias']));     $connection=yii::app()->db2;             $sql = "insert 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 following query (as seen on application log):

insert users (username, password, ssn, surname, firstname, email                    , city, country)  values(:alias, :password, :ssn, :surname, :firstname, :email, :city, :country); 

fyi $model->placeofbirth supposed in both city , county values. that's not typo (just silly thing have do).

just provide answer - because error pretty common - here few causes:

1) :parameter name not match bind mistake (typo?). happened here. has :alias in sql statement, bound :username. when param binding attempted, yii/pdo not find :username in sql statement, meaning "one parameter short" , threw error.

2) forgetting add bindvalue() parameter. easier in yii other constructs $critera, have array or params ($criteria->params = array(':bind1'=>'test', ':bind2'=>'test)).

3) weird conflicts cdataprovider pagination and/or sorting when using together , joins. there no specific, easy way characterize this, when using complex queries in cdataproviders have had weird issues parameters getting dropped , error occurring.

one helpful way troubleshoot these issues in yii enable parameter logging in config file. add db array in config file:

'enableparamlogging'=>true, 

and make sure cweblogroute route set in log section. print out query gave , error, , of parameters attempting bind. super helpful!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -