Five ways to update the database in thinkphp.

小云云
Release: 2023-03-17 15:22:02
Original
3250 people have browsed it

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!

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
Popular Tutorials
More>
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!