updateByPk() - possible bug ?

Recently I’ve notice strange thing about UpdateByPk() method, maybe it’s mine error or a bug…

If I want to update I field in database like below:


it just doesn’t work for me and updateByPk() method returns 0.

If works fine, when I do it like that:



What I’m missing ?

It should be noted that this method returns the number of rows affected by the query, not whether the statement ran successfully or not.

If the value you are sending for the update is the same as the value currently in the database, it will return 0. If you are changing the value it should return the number of rows that are updated.

I think why it works in the second instance and possibly not in the first is because you are changing the value to NULL first so that it updates the value on the second query. I’m not sure about the first.

I am receiving absolutely the same "bug", I would say.

$count = Project::model()->updateByPk(



	'user_id = :user_id',



if ($count == 1)


	$results['status'] = self::SAVE_SUCCESS;



	$results['count'] = $count;


And guess what. updateByPk return 0 while the row in the table is updated to the new value. I tested this dozens of times and got all the same 0.

I use Yii 1.1.6 on Windows with MySQL 5.5.