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 ~