From 6f1f5ebfdf5072a6f3abf81725c586d122f35712 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 18 Dec 2015 09:14:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0use=5Fdb=5Fswitch=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20=E6=94=AF=E6=8C=81=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=B7=9F=E9=9A=8Fapp=5Fstatus=E9=85=8D=E7=BD=AE=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 5 +++-- library/think/db.php | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) 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);