Home >Backend Development >PHP Tutorial >Getting Started with Thinkphp 5—Model (49)
【Database operation model model】
model model Database operation
tp framework main design pattern: MVC
C: controller controller shop/Lib/Action/specific controller
V: view view shop/Tpl/group/ Template file
M: model Data model shop/Lib/Model/Specific model
【Create model】
Principle of creation: One data table corresponds to one data model
Create model:
When the following message appears , indicating that our database does not have a username and password configured in config.php
[Database usage steps]:
[Database configuration config.php]:
[Get relevant information from the database— Query】
We use the select() method to obtain data information from the database, which 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() //Get all records and all field results
$goods -> select(15) //Get the record results with the primary key equal to 15
$goods -> select(“10,15, 20”) //Get the record information with the primary key within the range of 10, 15, and 20
$goods -> find(16); //Return to us the record information with the primary key equal to 16 in the form of a one-dimensional array
$ goods -> getByXXX(); //Query based on the where condition of the specific XXX field, and the one-dimensional array result is returned. This method will use the __call() automatic condition method in Model.class.php.
【Capitalization issue】:
【Detailed demonstration of obtaining data through model model】:
【Instancing model method】
?
The above introduces Getting Started with Thinkphp 5 - Model (49), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.