: This article mainly introduces ThinkPHP -- ActiveReocrd mode (add, delete, modify, and query). If you are interested in PHP tutorials, refer to it. ActiveReocrd mode
This mode simplifies CURD operations and adopts an object-based operation mode for ease of use.
And understanding.
// Add a data entry
$ User = M ('user ');
$ User-> user = 'Naruto ';
$ User-> email = 'huoyin @ qq.com ';
$ User-> date = date ('Y-m-d H: I: s ');
$ User-> add ();
// Combined with create
$ User = M ('user ');
$ User-> create ();
$ User-> date = date ('Y-m-d H: I: s ');
$ User-> add ();
// Find the value of primary key 4
$ User = M ('user ');
Var_dump ($ user-> find (4 ));
// Search for user = crayon records
$ User = M ('user ');
Var_dump ($ user-> getByUser ('crayon SHIN '));
// Output the user
Echo $ user-> user;
// Query multiple primary keys
$ User = M ('user ');
Var_dump ($ user-> select ('1, 2, 3 '));
// Modify a data record
$ User = M ('user ');
$ User-> find (1 );
$ User-> user = 'crayons old new ';
$ User-> save ();
// Delete the currently found data
$ User = M ('user ');
$ User-> find (11 );
$ User-> delete ();
// Delete data with a primary key of 10
$ User = M ('user ');
$ User-> delete (10 );
// Delete data with a primary key of 10 or 11
$ User = M ('user ');
$ User-> delete ('10, 11 ');
The above introduces ThinkPHP -- ActiveReocrd mode (add, delete, modify, and query), including some content, and hope to be helpful to PHP tutorials.