当前位置:网站首页>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的
边栏推荐
- Jump table instance
- Object.keys()的用法
- @EnableAspectAutoJAutoProxy_ Exposeproxy property
- Working group and domain analysis of Intranet
- What is torch NN?
- 表单传递时,如何隐式将值传过去
- 嵌入式软件架构设计-函数调用
- I let the database lock the table! Almost fired!
- Research Report on market supply and demand and strategy of tetramethylpyrazine industry in China
- Intranet penetrating FRP: hidden communication tunnel technology
猜你喜欢
Start by counting
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
Transformer中position encoding实践
Penetration test --- database security: detailed explanation of SQL injection into database principle
Anta is actually a technology company? These operations fool netizens
基于wifi控制的51单片机温度报警器
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
What is torch NN?
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
Hidden communication tunnel technology: intranet penetration tool NPS
随机推荐
中位数与次序统计量
Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
Vscode setting outline shortcut keys to improve efficiency
Sequence diagram data modeling and industrial chain analysis
Vscode prompt Please install clang or check configuration 'clang executable‘
Principle and general steps of SQL injection
The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
GO开发:如何利用Go单例模式保障流媒体高并发的安全性?
APOC自定义函数和过程
Common knowledge of unity Editor Extension
Height residual method
How to contribute to the source code of ongdb core project
Redis: SDS source code analysis
表单传递时,如何隐式将值传过去
Go language loop statement (under Lesson 10)
如何为ONgDB核心项目源码做贡献
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
FIREBIRD使用经验总结
散列表