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.