_php Example of table method of thinkphp curd method

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.