This paper describes the method of thinkphp model initialization. Share to everyone for your reference, as follows:
/* $dsn = ' mysql://bookman:book123@localhost:3306/weapons '; $guns _tab = M (' Guns ', ' ', $dsn); $gun 1 = $guns _tab->select (); echo $guns _tab-Getlastsql (); Dump ($gun 1); *//* $guns _tab = M (' Guns '); $gun 1 = $guns _tab->select (); echo $guns _tab-Getlastsql (); Dump ($gun 1); */ $guns _tab = new Gunsmodel (); $gun 1 = $guns _tab->select () page (' n '); echo $guns _tab-Getlastsql (); Dump ($gun 1); $guns _tab-Showinfo ();/* $guns _tab = new Detectmodel (' Guns '); $gun 1 = $guns _tab select (); echo $guns _tab-Getlastsql (); Dump ($gun 1); $guns _tab-Showinfo (); * *
1. How to connect from a configuration file
$dsn = ' mysql://bookman:book123@localhost:3306/weapons '; $guns _tab = M (' Guns ', ' ", $DSN); $gun 1 = $guns _tab->select () ; Echo $guns _tab-getlastsql ();d UMP ($gun 1);
2. Connect to the database according to the configuration file, the table name must distinguish clearly
$guns _tab = M (' Guns '), $gun 1 = $guns _tab->select (); Echo $guns _tab, Getlastsql ();d UMP ($gun 1);
3. I have a custom model that implements my own business methods, and I have a guns table so that I can initialize the model like this. You can get the data from the guns table, and you can also use the business methods in my custom model.
$guns _tab = new Detectmodel (' Guns '), $gun 1 = $guns _tab, select (), Echo $guns _tab, Getlastsql ();d UMP ($gun 1); $guns _tab, Showinfo ();
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.