APP_DEBUG = true
APP_TRACE = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = v1kcom
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
PREFIX = z_
CHARSET = utf8
DEBUG = true
#库2配置
[DATABASE2]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = v2kcom
USERNAME = root
PASSWORD = root
HOSTPORT = 3306
PREFIX = z_
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
二:配置config.php,加入二库参数/config/database.php
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => env('database.type', 'mysql'),
// 服务器地址
'hostname' => env('database.hostname', '127.0.0.1'),
// 数据库名
'database' => env('database.database', ''),
// 用户名
'username' => env('database.username', 'root'),
// 密码
'password' => env('database.password', ''),
// 端口
'hostport' => env('database.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => env('database.prefix', ''),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => env('app_debug', true),
// 开启字段缓存
'fields_cache' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
],
// 更多的数据库配置信息 (二库在这里配置)
'mysql2' => [
// 数据库类型
'type' => env('database2.type', 'mysql'),
// 服务器地址
'hostname' => env('database2.hostname', '127.0.0.1'),
// 数据库名
'database' => env('database2.database', ''),
// 用户名
'username' => env('database2.username', 'root'),
// 密码
'password' => env('database2.password', ''),
// 端口
'hostport' => env('database2.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('database2.charset', 'utf8'),
// 数据库表前缀
'prefix' => env('database2.prefix', ''),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => env('app_debug', true),
// 开启字段缓存
'fields_cache' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
],
],
三:控制器调用// 已经设置表前缀
result=Db::connect(′mysql′)−>name(′ad′)−>select();//未设置表前缀result = Db::connect('mysql')->table('z_ad')->select();
*************************************************************************************** 快速通道 *************************
***************************************************************
Thinkphp6笔记一:安装
http://www.thinkphp.cn/topic/68371.html
Thinkphp6笔记二:开启多应用模式
http://www.thinkphp.cn/topic/68451.html
Thinkphp6笔记三:开启.env
http://www.thinkphp.cn/topic/68452.html
Thinkphp6笔记四:配置/隐藏index.php
http://www.thinkphp.cn/topic/68453.html
Thinkphp6笔记五:路由配置
http://www.thinkphp.cn/topic/68454.html
Thinkphp6笔记六:空控制器与MISS路由
http://www.thinkphp.cn/topic/68455.html
Thinkphp6笔记七:控制器/模型基类配置
http://www.thinkphp.cn/topic/68456.html
Thinkphp6笔记八:公共函数配置
http://www.thinkphp.cn/topic/68457.html
Thinkphp6笔记九:语言包文件定义
http://www.thinkphp.cn/topic/68458.html
Thinkphp6笔记十:多语言配置(中文、英文)
http://www.thinkphp.cn/topic/68460.html
Thinkphp6笔记十一:中间件配置
http://www.thinkphp.cn/topic/68462.html
Thinkphp6笔记十二:多数据库配置
http://www.thinkphp.cn/topic/68463.html
Thinkphp6笔记十三:验证器(控制器验证)
http://www.thinkphp.cn/topic/68469.html
Thinkphp6笔记十三:验证器(场景验证)
http://www.thinkphp.cn/topic/68470.html
Thinkphp6笔记十三:验证器(模型验证)
http://www.thinkphp.cn/topic/68471.html
Thinkphp6笔记十四:Redis配置
http://www.thinkphp.cn/topic/68472.html
Thinkphp6笔记十五:html模板路径自定义配置
http://www.thinkphp.cn/topic/68473.html
Thinkphp6笔记十六:IP黑名单
http://www.thinkphp.cn/topic/68490.html
Thinkphp6笔记十七:模板标签使用
http://www.thinkphp.cn/topic/68493.html
Thinkphp6笔记十八:默认分页1
http://www.thinkphp.cn/topic/68495.html
最佳答案
