ThinkPHP -- ActiveReocrd mode (add, delete, modify, and query)

Source: Internet
Author: User
: 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.

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.