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