This article mainly introduces the thinkPHP model initialization method, and analyzes thinkPHP model initialization and database operation related skills in the form of instances. it has some reference value. if you need ThinkPHP, you can refer to thinkPHP.
This document describes how to initialize the thinkPHP model. We will share this with you for your reference. The details are as follows:
/* $dsn = 'mysql://bookman:book123@localhost:3306/Weapons'; $guns_tab = M('guns','',$dsn); $gun1 = $guns_tab ->select(); echo $guns_tab -> getLastSql(); dump($gun1);*//* $guns_tab = M('guns'); $gun1 = $guns_tab ->select(); echo $guns_tab -> getLastSql(); dump($gun1);*/ $guns_tab = new GunsModel(); $gun1 = $guns_tab ->select() -> page('1,1'); echo $guns_tab -> getLastSql(); dump($gun1); $guns_tab -> showInfo();/* $guns_tab = new DetectModel('guns'); $gun1 = $guns_tab -> select(); echo $guns_tab -> getLastSql(); dump($gun1); $guns_tab -> showInfo();*/
1. disconnection from the configuration file
$dsn = 'mysql://bookman:book123@localhost:3306/Weapons';$guns_tab = M('guns','',$dsn);$gun1 = $guns_tab ->select();echo $guns_tab -> getLastSql();dump($gun1);
2. connect to the database according to the configuration file. The table names must be clearly distinguished.
$guns_tab = M('guns');$gun1 = $guns_tab ->select();echo $guns_tab -> getLastSql();dump($gun1);
3. I have a custom model that implements my own business methods. I also have a guns table that can initialize the model in this way. You can obtain the data in the guns table or use the business methods in the custom model.
$guns_tab = new DetectModel('guns');$gun1 = $guns_tab -> select();echo $guns_tab -> getLastSql();dump($gun1);$guns_tab -> showInfo();
I hope this article will help you design PHP programs based on the thinkPHP framework.