Yii2.0 批量操作

yii\db\ActiveRecord::updateAll($attributes, $condition = '')
  //将所有satus为2的记录的status更新为1
  //update user set status = 1 where status = 2
    eg:  User::updateAll(['status' => 1], 'status = 2');

yii\db\ActiveRecord::updateAllCounters($counters, $condition = '')
  //所有用户的age字段加1
  //update user set age = age + 1
    eg:  User::updateAllCounters(['age' => 1]);

yii\db\ActiveRecord::deleteAll($condition = '')
  //删除所有status为3的记录
  //delete from user where status = 3
    eg:  User::deleteAll('status = 3');



导航