thinkphp Simple Code Instance _php instance for cross-Library operations

Source: Internet
Author: User

Instance One: Configure config.php files Configure multiple database configurations

' Db_config2 ' => ' mysql://root:1234@localhost:3306/thinkphp ',

The method is called in the controller:

$New = M (' table name ', ' prefix no prefix not filled ', ' db_config2 ');

This is equivalent to a new connection to the database remote cross-Library if it is in the same server database you can switch directly:

$User = M (' Database name. Table name ', ' prefix not fill ');

Example Two: Cross-Library in model model fill out the following code in the modeling class

protected $connection = ' mysql://user name: Password @ip Address: Port/database name ';
protected $dbName = ' database name ';//cross-Library operations
protected $tablePrefix = ';//cross-Library database table name prefix

Note: The remote Cross Library uses the protected $connection configuration database, and the intranet database in the server can directly configure the following code across the library.

protected $dbName = ' database name ';//cross-Library operations
protected $tablePrefix = ';//cross-Library database table name prefix

The above is a small series for you to bring the thinkphp across the library to operate a simple example of the entire content of the code, I hope to help you, a lot of support cloud Habitat Community ~

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.