在项目开发中须要Thinkphp5读取多个数据库的数据,本文详细介绍Thinkphp5多数据库切换php
1、在database.php配置默认数据库链接mysql
'type' => 'mysql',
'hostname' => '服务器IP地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口',
2、在config.php配置第二个数据库链接sql
'DB_Config_1'=>[
'type' => 'mysql',
'hostname' => '服务器IP地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口'
],
3、多数据库使用
//默认数据库读取数据
$test = Db::name("test")->select();
//第二个数据库读取数据
$test1=Db::connect("DB_Config_1")->name("test")->select();数据库
在项目开发中须要Thinkphp5读取多个数据库的数据,本文详细介绍Thinkphp5多数据库切换服务器
1、在database.php配置默认数据库链接开发
'type' => 'mysql',
'hostname' => '服务器IP地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口',
2、在config.php配置第二个数据库链接test
'DB_Config_1'=>[
'type' => 'mysql',
'hostname' => '服务器IP地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口'
],
3、多数据库使用
//默认数据库读取数据
$test = Db::name("test")->select();
//第二个数据库读取数据
$test1=Db::connect("DB_Config_1")->name("test")->select();配置