Home> PHP Framework> YII> body text

How to update data in yii

angryTom
Release: 2020-02-17 11:41:38
Original
4398 people have browsed it

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);
Copy after login

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']);
Copy after login

3. Use save( );

$customer = Customer::find() ->where(['id' => 1]) ->one(); $customer->name = 'zhangsan'; $customer->save();
Copy after login

For more YII related tutorials and programming knowledge, please visitProgramming 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!