I have looked at the other questions concerning this error message, but all appear to have something to do with a miss match between a parameter and its binding, or missing bindings, or something like that. Here is my code. Can anyone here see the error? This is in a CDbMigration class.
$this->insert('company', array(
'name' => 'Site Administrator',
));
$companyId = $this->dbConnection->getLastInsertID();
$sql = 'insert into `user` (`company-id`, `login-id`, `password`) ';
$sql .= 'values (:company-id, :login-id, :password)';
$command = $this->dbConnection->createCommand($sql);
$command->bindValue(':company-id', $companyId, PDO::PARAM_INT);
$command->bindValue(':login-id', 'admin');
$command->bindValue(':password', 'admin');
$command->execute();
The first insert performs properly, the second gives the following error:
Exception: CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined. The SQL statement executed was: insert into `user` (`company-id`, `login-id`, `password`) values (:company-id, :login-id, :password). Bound with :company-id='6', :login-id='admin', :password='admin' (C:\eclipse-php-3.0.2\workspace\interview\lib\yii\db\CDbCommand.php:357)
For the record, I realize that I need to do something to the password so that it is not stored in plain text. I will deal with that later. In addition, the user table is defined in the migration class as follows:
$this->createTable('user', array(
'id' => 'pk',
'company-id' => 'integer not null',
'login-id' => 'string unique not null',
'password' => 'string not null',
'full-name' => 'string',
'mobile-phone' => 'string',
'other-phone' => 'string',
'email' => 'string unique',
));
$this->addForeignKey('fk_user_company', 'user', 'company-id', 'company', 'id'
, 'restrict');