The table method of the ThinkPHP CURD method is also one of the coherent operation methods of the model class.Data Tables Used for specified operations.
The usage is as follows:
Generally, the system can automatically identify the corresponding data table when operating the model. Therefore, the table method is generally used:
1. Data Tables for switchover operations;
2. Operate on multiple tables;
For example:
$ Model-> table ('Think _ user')-> where ('status> 1')-> select ();
You can also specify the database in the table method, for example:
$ Model-> table ('db _ name. think_user ')-> where ('status> 1')-> select ();
Note that the table method does not change the database connection. Therefore, make sure that the currently connected user has the permission to operate the corresponding database and data table.
After the data table is switched, the system automatically obtains the field cache information of the switched data table.
To operate multiple tables, use the following method:
$ Model-> field ('user. name, role. title ')-> table ('Think _ user, think_role role')-> limit (10)-> select ();
To avoid conflict with mysql keywords, we recommend that you use arrays, for example:
$ Model-> field ('user. name, role. title ')-> table (array ('Think _ user' => 'user', 'Think _ role' => 'role')-> limit (10) -> select ();