updateByPk() method returns 0 on successful update

I am receiving a strange behavior, I would say it’s a bug.

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



        'user_id = :user_id',



if ($count == 1)


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



        $results['count'] = $count;


In the above code $count is equal to 0 while the row in the table is successfully updated to the new value. I tested this dozens of times and got all the same 0.

I use Yii 1.1.6 with MySQL 5.5 on Windows.

Note: there is no need to post the same post on different threads - http://www.yiiframework.com/forum/index.php?/topic/5700-updatebypk-possible-bug/page__view__findpost__p__90541

Have you read the second comment on that thread - http://www.yiiframework.com/forum/index.php?/topic/5700-updatebypk-possible-bug/page__view__findpost__p__29361

Have you checked that the values that you are updating are different then the one already in the database?

If you have noticed that thread is for Yii 1.0. This is why I felt necessary to repost as I use Yii 1.1.6.

Indeed I did! If you have carefully read my message I wrote:

It means, the previous value was different from the one inserted. I make sure beforehand so that the values are different. If same, it does not enter this function. And, again, the value in the database is being altered successfully to a new one, completely new value.

I didn’t you simple update() function on the record itself, because the record data is received from the client and it’s assumed to be new. Here is the beginning of the code.

$model = new Project;

$model->scenario = 'save';

$model->attributes = $_POST['Project'];

$model->user_id = Yii::app()->user->id;

$results = array();

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

if ($model->validate())


The previous chunk of code goes inside the validate() block. The interesting thing is I can replace the updateByPk with updateAll like:

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


	'id = :id AND user_id = :user_id',

	array(':id'=>$model->id, ':user_id'=>$model->user_id)


I receive 0 anyway. But the column value is being successfully updated.

Thanks you for time. I really hope it is my fault and is not a bug.