Tinkphp curd operations

Source: Internet
Author: User
Adding, deleting, modifying, and querying curd. outline of this lesson: 1. Introduction to CURD of ThinkPHP3 II. reading data from ThinkPHP3 (emphasis) Read $ mnewModel (& amp; #39...

Curd adds, deletes, modifies, and queries.

Outline of this lesson:

1. Introduction to CURD of ThinkPHP 3 (learn more)

II. ThinkPHP 3 reading data (important)

Read Data

$ M = new Model ('user ');

$ M = M ('user ');

Select

$ M-> select (); // Obtain all data and return it as an array

Find

$ M-> find ($ id); // Obtain a single data record

GetField (field name) // Obtain a specific field value

$ Arr = $ m-> where ('Id = 2')-> getField ('Username ');

III. ThinkPHP 3 create data (important)

Create

$ M = new Model ('user ');

$ M = M ('user ');

$ M-> Field name = value

$ M-> add ();

The returned value is the new ID number.

IV. ThinkPHP 3 delete data (important)

$ M = M ('user ');

$ M-> delete (2); // delete data with id 2

$ M-> where ('Id = 2')-> delete (); // the data with the id of 2 is also deleted.

The returned value is the number of affected rows.

5. ThinkPHP 3 update data (important)

$ M = M ('user ');

$ Data ['id'] = 1;

$ Data ['username'] = 'ztz2 ';

$ M-> save ($ data );

The returned value is the number of affected rows.

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.