Yii2: update field with query builder

前端 未结 6 823
Happy的楠姐
Happy的楠姐 2021-01-07 17:26

How can I update field with query builder in Yii2? I can\'t find this in documentation.

Thanks!

UPD

This is the solution:

         


        
6条回答
  •  执念已碎
    2021-01-07 17:57

    Also, if you need to use the column itself in the update query, you must use yii\db\Expression.

    \Yii::$app->db->createCommand()
        ->update('user', ['visits' => new \yii\db\Expression('visits + 1')], 'age > 30')
        ->execute();
    

提交回复
热议问题