设为首页 加入收藏

TOP

Thinkphp5多数据库切换
2019-09-17 18:20:03 】 浏览:20
Tags: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();

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇linux中使sqlplus能够上下翻页 下一篇MySQL向数据库表的某字段追加数据

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目