Hi,
I am newbie here, I need to update a row in my table
below is the code Im using
$connection=Yii::app()->db;
$sql=‘update tablename set userid =:userid where ID=:ID’;
$command=$connection->createCommand($sql);
$command->bindParam(":userid",$session[‘userId’],PDO::PARAM_STR);
$command->bindParam(":ID",$ID,PDO::PARAM_STR);
$command->execute();
But I am getting below error
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘userId’ in ‘field list’.
But there is userId in the DB not sure if my coding is wrong
Keith
(Kburton)
#2
Can you post your exact code and the schema for the relevant table?
Also, use code tags when posting code; they can be inserted using the "<>" icon in the editor window.
Table name - usertable
field names - ID(int autoincrement), userid (int), username (varchar(100)
Below is the code Im using
$connection=Yii::app()->db;
$sql='update usertable set userid =:userid where ID=:ID';
$command=$connection->createCommand($sql);
$command->bindParam(":userid",$session['userId'],PDO::PARAM_STR);
$command->bindParam(":ID",$ID,PDO::PARAM_STR);
$command->execute();
Interesting.
This error can show up when something has not been binded properly, so the generated sql looks like this:
UPDATE usertable SET userid = userId where ID = ‘your ID’;
The funny thing is the only camelcased "userId" is the array key.
Ok, first of all, try to use bindValue instead of bindParam and see if something changes.