Yii2 中的 updateAll()
可以接受三個參數,$attributes, $condition, $params = null
第一個參數是要更新的值,第二個是條件,如果第二個條件中用了占位符,就必須 要有第三個條件。
Test::updateAll(['status' => 1],['status' => 0,'flag' => 1]);
靈活操作
Country::updateAll( [ 'status'=>3 // 要更新的值 ], [ 'and', [ 'status' => 0 //更新條件 ], [ 'population'=>0 //更新條件 ], [ 'end_date' => 0 //更新條件 ] ] );