_php Example of table method of thinkphp curd method

Source: Internet
Author: User
The table method of the Thinkphp curd method also belongs to one of the coherent operation methods of model class, and the method A data table that is used primarily for specifying operations

The specific usage is as follows:

In general, the system can automatically recognize the current corresponding data table when manipulating the model, so the table method is usually used to:

1. Data sheet for switching 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 ();

It is important to note that the table method does not alter the connection to the database, so you want to ensure that the current connected user has permission to manipulate the database and data tables.

After switching the data table, the system automatically retrieves the field cache information for the Switched data table.

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 conflicts with MySQL keywords, it is recommended to use array-like definitions, for example:

$Model->field (' User.name,role.title ')->table (Array (' think_user ' = ' user ', ' think_role ' = ' role ')- >limit (->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.