Update Query Sql Table In Yii

I have 2 questions first one is that how can I update row in table in yii? I am using the following code but it is not working


$connection=Yii::app()->db;

$sql = "UPDATE auth_assignment SET itemname = 'Authenticated' WHERE userid = $user->accountID";

$command = $connection->createCommand($sql);

$command->execute();

Also how can I make my above query safe from sql injection attack.

please see it

Thanks for the reply. But I want to know what is wrong with my code since when I directly execute sql query it is working but not with code in yii.

How do I change table in which I am updating?

you can write a correct query both are difference please see it

It is still not working.