ThinkPHP CURD is easy to ignore

Source: Internet
Author: User
Provides various official and user-released code examples and code reference. You are welcome to exchange and learn ThinkPHP CURD easy to ignore.
Thinkphp CURD is easy to ignore
1. Use the object method to insert data D.
$ Form = D ('form ');
$ Data ['title'] = 'thinkphp ';
$ Data ['content'] = 'form content ';
$ Form-> add ($ data );

In fact, thinkphp also supports object-based direct data insertion into the database, as shown below:
$ Form = D ('form ');
$ Form-> title = 'thinkphp ';
$ Form-> content = 'form content ';
$ Form-> add ();

2. No conditions are specified for data update.
$ Form = M ("Form"); // assign values to the attributes of the data object to be modified
$ Data ['id'] = 5;
$ Data ['title'] = 'thinkphp ';
$ Data ['content'] = 'thinkphp3. 1 release ';
$ Form-> save ($ data); // save the modified data according to the conditions.

The save method automatically identifies the primary key field in the Data Object and serves as the update condition. Of course, you can also explicitly pass in the update condition, which is our most commonly used method:
$ Form = M ("Form ");
// Assign values to the attributes of the data object to be modified
$ Data ['title'] = 'thinkphp ';
$ Data ['content'] = 'thinkphp3. 1 release ';
$ Form-> where ('Id = 5')-> save ($ data); // save the modified data according to the conditions.

In fact, there is also an object method, as mentioned above, insert data in the same way as the object:
$ Form = M ("Form ");
// Assign values to the attributes of the data object to be modified
$ Form-> title = 'thinkphp ';
$ Form-> content = 'thinkphp3. 1 release ';
$ Form-> where ('Id = 5')-> save (); // save the modified data according to the conditions.

In addition, you can include the primary key field in the data to be saved, so that you do not need to write where
$ Form = M ("Form ");
// Assign values to the attributes of the data object to be modified
$ Form-> id = 5;
$ Form-> title = 'thinkphp ';
$ Form-> content = 'thinkphp3. 1 release ';
$ Form-> save (); // save the modified data based on the primary key of the data object.

Here is just a small summary. For more information, see http://www.jb100.net/html/content-28-248-1.html, which is detailed and helpful to everyone.

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.