Thinkphp5多数据库切换
在项目开发中需要thinkphp5读取多个数据库的数据,本文详细介绍thinkphp5多数据库切换
一、在database.php配置默认数据库连接
'type' => 'mysql',
'hostname' => '服务器ip地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口',
二、在config.php配置第二个数据库连接
'db_config_1'=>[
'type' => 'mysql',
'hostname' => '服务器ip地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口'
],
三、多数据库使用
//默认数据库读取数据
$test = db::name("test")->select();
//第二个数据库读取数据
$test1=db::connect("db_config_1")->name("test")->select();
在项目开发中需要thinkphp5读取多个数据库的数据,本文详细介绍thinkphp5多数据库切换
一、在database.php配置默认数据库连接
'type' => 'mysql',
'hostname' => '服务器ip地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口',
二、在config.php配置第二个数据库连接
'db_config_1'=>[
'type' => 'mysql',
'hostname' => '服务器ip地址',
'database' => '数据库名',
'username' => '用户名',
'password' => '密码',
'hostport' => '数据库端口'
],
三、多数据库使用
//默认数据库读取数据
$test = db::name("test")->select();
//第二个数据库读取数据
$test1=db::connect("db_config_1")->name("test")->select();
推荐阅读
-
ASP.NET MVC重写RazorViewEngine实现多主题切换
-
mysql数据库的多实例与主从同步。
-
多实例设置本地IP访问sqlserver数据库步骤(图 )
-
tp5(thinkPHP5)框架数据库Db增删改查常见操作总结
-
SpringBoot多配置切换的配置方法
-
mysql切换数据库提示警告:Reading table information for completion of table and column names
-
thinkphp3.2.3框架动态切换多数据库的方法分析
-
thinkPHP5实现数据库添加内容的方法
-
Nodejs多站点切换Htpps协议详解及简单实例
-
ThinkPHP6新增‘’多应用‘’与ThinkPHP5有啥区别