diff --git a/convention.php b/convention.php index 24b2f173..b12b3589 100644 --- a/convention.php +++ b/convention.php @@ -136,8 +136,9 @@ return [ // +---------------------------------------------------------------------- // | 数据库设置 // +---------------------------------------------------------------------- - - 'db_like_fields' => '', + + // 是否启用多状态数据库配置 如果启用的话 需要跟随app_status配置不同的数据库信息 + 'use_db_switch' => false, 'database' => [ // 数据库类型 'type' => 'mysql', diff --git a/library/think/db.php b/library/think/db.php index 6fadfcf0..f4264937 100644 --- a/library/think/db.php +++ b/library/think/db.php @@ -54,6 +54,9 @@ class Db { if (empty($config)) { $config = Config::get('database'); + if (Config::get('use_db_switch')) { + $config = $config[Config::get('app_status')]; + } } if (is_string($config)) { return self::parseDsn($config);