The table method of the thinkphp curd method is also part of a coherent operation of the model class, which is used primarily to specify the data table for the Operation .
The specific usage is as follows:
In general, the system can automatically recognize the current data table when operating the model, so the table method is usually used to:
1. Switch the operation of the data table;
2. The operation of multiple tables;
For example:
$Model->table (' Think_user ')->where (' status>1 ')->select ();
You can also specify a 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, so you want to make sure that the currently connected user has permission to manipulate the corresponding database and datasheet.
After the data table is switched, the field cache information for the switched datasheet is automatically retrieved.
If you need to operate on multiple tables, you can use this:
$Model->field (' User.name,role.title ')->table (' Think_user user,think_role role ')->limit ()->select () ;
In order to avoid the keyword conflicts with MySQL, it is advisable to use an array definition, for example:
$Model->field (' User.name,role.title ')->table (Array (' Think_user ' => ' user ', ' think_role ' => ' role '))- >limit (a)->select ();