当前位置:网站首页>tp配置多数据库
tp配置多数据库
2022-07-04 15:01:00 【wiscourper_】
1、在database.php中添加
'db2' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'test',
// 用户名
'username' => 'root',
// 密码
'password' => 'root',
// 端口
'hostport' => '3306',
// 连接dsn
'dsn' => '',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'tn_',
// 数据库调试模式
'debug' => true,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 自动读取主库数据
'read_master' => false,
// 是否严格检查字段是否存在
'fields_strict' => true,
// 数据集返回类型
'resultset_type' => 'array',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析
'sql_explain' => false,
]
2、另外一套还是用原来的
3、测试
$db2 = \think\Db::connect(config('database.db2'));
$res = $db2->name("user")->find();
var_dump(\think\Db::table("customer")->find());//原来的
var_dump($res);die;//db2的
边栏推荐
- 程序员怎么才能提高代码编写速度?
- Visual Studio 2019 (LocalDB)MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782
- Transformer中position encoding实践
- Model fusion -- stacking principle and Implementation
- Principle and general steps of SQL injection
- Accounting regulations and professional ethics [9]
- SQL implements split
- Task state rollback and data blocking tasks based on check point mechanism
- C language: implementation of daffodil number function
- 照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益
猜你喜欢
MFC implementation of ACM basic questions encoded by the number of characters
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Vscode setting outline shortcut keys to improve efficiency
Understand asp Net core - Authentication Based on jwtbearer
Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
D3D11_ Chili_ Tutorial (2): draw a triangle
What is torch NN?
Game theory
@EnableAspectAutoJAutoProxy_ Exposeproxy property
DIY a low-cost multi-functional dot matrix clock!
随机推荐
C language: implementation of daffodil number function
2021 Google vulnerability reward program review
China's plastic processing machinery market trend report, technological innovation and market forecast
线性时间排序
L1-072 scratch lottery
一图看懂ThreadLocal
Four point probe Industry Research Report - market status analysis and development prospect prediction
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
Intranet penetrating FRP: hidden communication tunnel technology
Using celery in projects
Opencv learning -- geometric transformation of image processing
Hair growth shampoo industry Research Report - market status analysis and development prospect forecast
Accounting regulations and professional ethics [11]
多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
Accounting regulations and professional ethics [6]
Overflow: the combination of auto and Felx
SQL implements split
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
实战:fabric 用户证书吊销操作流程
Research Report of exoskeleton robot industry - market status analysis and development prospect prediction