From 1cfef7aadc74b6e63248ed362b4bab4f3e222c9b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 25 Apr 2018 15:41:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 2 +- library/think/db/Query.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index a82dfb44..7720282d 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -451,7 +451,7 @@ abstract class Connection $this->debug(false, '', true); if ($query && !empty($this->config['deploy']) && !empty($this->config['read_master'])) { - $query->readMaster(true); + $query->readMaster(); } $this->numRows = $this->PDOStatement->rowCount(); diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 8ca880fd..21858779 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -145,17 +145,19 @@ class Query /** * 设置后续从主库读取数据 * @access public - * @param bool $master + * @param bool $allTable * @return void */ - public function readMaster($master = true) + public function readMaster($allTable = false) { - if ($master) { + if ($allTable) { + $table = '*'; + } else { $table = isset($this->options['table']) ? $this->options['table'] : $this->getTable(); - - static::$readMaster[$table] = true; } + static::$readMaster[$table] = true; + return $this; } @@ -2942,7 +2944,7 @@ class Query } } - if (isset(static::$readMaster[$options['table']])) { + if (isset(static::$readMaster['*']) || isset(static::$readMaster[$options['table']])) { $options['master'] = true; }