ThinkPHP is a free open source, fast, simple object-oriented lightweight PHP development framework, released under the Apache2 open source protocol, and was born to simplify enterprise-level application development and agile WEB application development. In this article, we mainly introduce five ways to update the database in thinkphp.
Thinkphp five ways to update the database.
The first method:
$model->where('id=1')->save($data);
The second method:
$Model->where('id=1')->data($data)->save();
Third method:
$Model->create();
$Model->save();
The form must contain a hidden field named by the primary key
Four methods:
$Model->where('id=5')->setField('name','ThinkPHP');
$Model->where( 'id=5')->setField(array('name','email'),array('TP','TP@163.com'));
The fifth type Method:
$Model->setInc('score','id=5',3); // Add 3 points
$Model->setInc('score','id= 5'); // Add 1
$ model to the points->setDec('score','id=5',5); // Subtract 5
$ models from the points->setDec('score' ,'id=5'); // Points are reduced by 1
You can try the above five methods and hope they will be helpful to everyone.
Related recommendations:
Summary of Thinkphp questions in php interview questions
##ThinkPHP5 CURL operation method for database
Thinkphp implementation method of executing native SQL statements
The above is the detailed content of Five ways to update the database in thinkphp.. For more information, please follow other related articles on the PHP Chinese website!