The example of this article describes the method of thinkphp model initialization. Share to everyone for your reference, specific 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 (' 1,1 ');
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. Connection mode from configuration file
$dsn = ' mysql://bookman:book123@localhost:3306/weapons ';
$guns _tab = M (' Guns ', ', $dsn);
$gun 1 = $guns _tab->select ();
echo $guns _tab-> getlastsql ();
Dump ($gun 1);
2. Connect 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 ();
Dump ($gun 1);
3. I have a custom model that implements my own business methods, and I have a guns table so I can initialize the model like this. You can get the data from the guns table, and you can use the business methods in my custom model.
$guns _tab = new Detectmodel (' Guns ');
$gun 1 = $guns _tab-> Select ();
echo $guns _tab-> getlastsql ();
Dump ($gun 1);
$guns _tab-> showinfo ();
I hope this article will help you with the PHP program design based on thinkphp framework.