From 095243277968a332c85741aee83dd85647375087 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 10 Feb 2016 11:24:10 +0900 Subject: [PATCH] Fix master/slave DB handling during transaction --- classes/db/DB.class.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php index 823dcd7c9..a852608d9 100644 --- a/classes/db/DB.class.php +++ b/classes/db/DB.class.php @@ -999,7 +999,7 @@ class DB */ function _getConnection($type = 'master', $indx = NULL) { - if($type == 'master') + if($type == 'master' || $this->transactionNestedLevel) { if(!$this->master_db['is_connected']) { @@ -1014,11 +1014,20 @@ class DB $indx = $this->_getSlaveConnectionStringIndex($type); } + if($this->slave_db[$indx]['host'] == $this->master_db['host'] && $this->slave_db[$indx]['port'] == $this->master_db['port']) + { + if(!$this->master_db['is_connected']) + { + $this->_connect($type); + } + $this->connection = 'Master ' . $this->master_db['host']; + return $this->master_db["resource"]; + } + if(!$this->slave_db[$indx]['is_connected']) { $this->_connect($type, $indx); } - $this->connection = 'Slave ' . $this->slave_db[$indx]['host']; return $this->slave_db[$indx]["resource"]; } @@ -1271,7 +1280,7 @@ class DB { $connection = &$this->slave_db[$indx]; } - + $result = $this->__connect($connection); if($result === NULL || $result === FALSE) {