Detailed explanation of the table method of ThinkPHP CURD method_PHP tutorial

WBOY
Release: 2016-07-13 10:24:48
Original
710 people have browsed it

The table method of the ThinkPHP CURD method is also one of the coherent operation methods of the model class. This method is mainly used to specify the data table for the operation.

The specific usage is as follows:

Generally, the system can automatically identify the current corresponding data table when operating the model, so the table method is usually used for:

1. Data table of switching operation;
2. Operate multiple tables;

For example:

$Model->table('think_user')->where('status>1')->select();

Copy after login

You can also specify the database in the table method, for example:

$Model->table('db_name.think_user')->where('status>1')->select();

Copy after login

It should be noted that the table method will not change the database connection, so you must ensure that the currently connected user has permission to operate the corresponding database and data table.

After switching data tables, the system will automatically re-obtain the field cache information of the switched data table.

If you need to operate multiple tables, you can use it like this:

$Model->field('user.name,role.title')->table('think_user user,think_role role')->limit(10)->select();

Copy after login

In order to avoid conflict with mysql keywords, it is recommended to use array definition, for example:

$Model->field('user.name,role.title')->table(array('think_user'=>'user','think_role'=>'role'))->limit(10)->select();
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825323.htmlTechArticleThe table method of ThinkPHP CURD method is also one of the coherent operation methods of the model class. This method is mainly used to specify operations. data sheet. The specific usage is as follows: Generally, the operating model...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template