Thinkphp getting started 5-model (49), thinkphp49_PHP tutorial

Source: Internet
Author: User
Thinkphp entry 5-model (49), thinkphp49. Thinkphp entry 5-model (49), thinkphp49 [Database operation model] model database operation tp framework main design mode: MVCC: controller shopLib Thinkphp entry 5-model (49 ), thinkphp49
[Database operation model]

Model database operations

Main design pattern of tp framework: MVC

C: controller shop/Lib/Action/specific controller

V: view shop/Tpl/group/template file

M: model data Model shop/Lib/model/specific Model

[Create model]

Creation principle: a data table corresponds to a data model.

Create model:

When the following information appears, it indicates that our database has not configured the username and password config. php.

[Database usage steps]: [database configuration config. php]: [obtain related information from the database-query]

We use the select () method to obtain data information from the database. this method returns a two-dimensional array,

If we want to obtain a record, we use the find () method, which returns a one-dimensional array.

$ Goods-> select () // Obtain all records and field results

$ Goods-> select (15) // Obtain the record result with the primary key equal to 15

$ Goods-> select ("10, 15, 20") // Obtain the record information of the primary key in the range of 10, 15, and 20

$ Goods-> find (16); // returns record information with a primary key equal to 16 in the form of a one-dimensional array.

$ Goods-> getByXXX (); // query the where condition based on the specific XXX field. one-dimensional array results are returned. This method follows the _ call () automatic condition method in Model. class. php.

[Case sensitivity problem]: [demonstration of data obtained through the model]: [method of instantiating the model]

Example: D ('Goods '); instantiate a Goods model object

D (); instantiate the base class object. you must specify the "data table name" when using this object"

And the primary key name, which is complex and is not recommended for direct use.

3. instantiate a base class object through the shortcut function M ()

For example, M () instantiates the object corresponding to Model. class. php. this method is not recommended.

[When creating a model, it is possible that the table prefix corresponding to this model is inconsistent with that of other tables. Therefore, this model needs to define its own real table name ]:

Fifth-model (49), thinkphp49 [Database operation model] model database operation tp framework main design mode: mvc c: controller shop/Lib /...

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.