Thinkphp method of modifying only one value: 1. Modify the data by calling the save() function under Model; 2. Through "$res = $user->where('ID=5') ->save($data);" method to add where condition, and then call the save function to modify the data value.
The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.
How to modify only one value in thinkphp?
Database operation: modify a piece of data (thinkPHP)
The first method: the database contains an automatically growing field ID, and the ID is used as the where condition
<?php class UserAction extends Action{ public function updateUser(){ $user = M('Userinfo'); //实例化Model $data = array('ID'=>5,'username'=>'王美人','email'=>'meiren@163.com');//$data中包含有自动增长字段uid $res = $user->save($data);//调用Model下的save()函数进行数据的修改 var_dump($res); } } ?>
Second method: If there is no automatic growth of field ID in the database, you need to add where conditions
<?php class UserAction extends Action{ public function updateUser(){ $user = M('userinfo');//实例化Model $data = array('username'=>'王美人','email'=>'mei@163.com');//$data中没有自动增长字段uid $res = $user->where('ID=5')->save($data);//需要增加where条件。调用Model下的save()函数进行数据的修改 var_dump($res);//返回影响的行数 } } ?>
Recommended learning: "thinkPHP Video Tutorial"
The above is the detailed content of How to modify only one value in thinkphp. For more information, please follow other related articles on the PHP Chinese website!