Home > Article > PHP Framework > How to update data in yii
How to update data in yii
1. Use update()
//runValidation boolen 是否通过validate()校验字段 默认为true //attributeNames array 需要更新的字段 $model->update($runValidation , $attributeNames);
2. Use updateAll();
Recommended related article tutorials: yii tutorial
//update customer set status = 1 where status = 2 Customer::updateAll(['status' => 1], 'status = 2'); //update customer set status = 1 where status = 2 and uid = 1; Customer::updateAll(['status' => 1], ['status'=> '2','uid'=>'1']);
3. Use save( );
$customer = Customer::find() ->where(['id' => 1]) ->one(); $customer->name = 'zhangsan'; $customer->save();
For more YII related tutorials and programming knowledge, please visit Programming Learning Course.
The above is the detailed content of How to update data in yii. For more information, please follow other related articles on the PHP Chinese website!