Five ways to update a database thinkphp.

Source: Internet
Author: User
Thinkphp is a free, open-source, fast, simple object-oriented, lightweight PHP development framework that follows the Apache2 Open source protocol and is designed to simplify enterprise application development and Agile Web application development. In this article we mainly introduce five kinds of methods of thinkphp update database.

Thinkphp Five ways to update a database.

The first method:

$ model->where (' id=1 ')->save ($data);

The second method:

$ model->where (' id=1 ')->data ($data)->save ();

The third method:

$ model->create ();

$ model->save ();

The form must contain a hidden field with a primary key name

The fourth method:

$ model->where (' id=5 ')->setfield (' name ', ' thinkphp ');

$ model->where (' id=5 ')->setfield (Array (' name ', ' email '), array (' TP ', ' TP@163.com '));


The Fifth method:

$ model->setinc (' score ', ' id=5 ', 3); Points plus 3
$ model->setinc (' score ', ' id=5 '); Points plus 1
$ model->setdec (' score ', ' id=5 ', 5); Points minus 5
$ model->setdec (' score ', ' id=5 '); Points minus 1

Above these five methods we can try to use a bit of hope to help everyone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.