In the development of the program, it is unavoidable to encounter across database operations (including the same and different kinds of databases), the use of thinkphp cross-database operations will be much easier
The following is a simple configuration.
1 onfig.php files
' Load_ext_config ' => ' db,db_config ',
Load extended configuration file, multiple files separated by commas
Where the db.php is placed in the MySQL configuration
Db_config placed the configuration of another MySQL database
2 of which db.php contents are as follows
Return Array (
' Db_type ' => ' MySQL ',
' Db_host ' => ' localhost ',
' Db_name ' => ' your_mysql_dbname ',
' Db_user ' => ' your_mysql_user_name ',
' Db_pwd ' => ' 123456 ',
' Db_port ' => ' 3306 ',
' Db_prefix ' => ',
);
db_config.php content is as follows
Return Array (
' Db_config ' =>array (
' Db_type ' => ' MySQL ',
' Db_host ' => ' 127.0.0.1 ',
' Db_port ' => ' 3306 ',
' Db_name ' => ' OA ',
' Db_user ' => ' root ',
' Db_pwd ' => ',
' Db_prefix ' => ' tp_ '
)
);
3 Create a special model under Lib/model
Class Usermodel extends Model {
protected $connection = ' db_config ';
}
4 You can tune each model in action
$user = D (' user ');
Continue with other actions ...
$user->select (); Find all the Users