diff --git a/Database/Command.php b/Database/Command.php index 26bc33a5..8afa8f60 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -218,7 +218,8 @@ class Command extends Component */ private function search($type) { - if (!(($connect = $this->db->getConnect($this->sql)) instanceof PDO)) { + $connect = $this->db->getConnect($this->sql); + if (!($connect instanceof PDO)) { return null; } if (!($query = $connect->query($this->sql))) return null; diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 87450701..74a9f9b1 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -198,9 +198,6 @@ class Connection extends Pool */ public function getConnection(array $config, $isMaster = false) { - if ($this->creates === 0) { - $this->creates = Timer::tick(10000, [$this, 'Heartbeat_detection']); - } $coroutineName = $this->name($config['cds'], $isMaster); if (!isset($this->hasCreate[$coroutineName])) { $this->hasCreate[$coroutineName] = 0; @@ -243,6 +240,9 @@ class Connection extends Pool if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) { $number > 0 && $client->beginTransaction(); } + if ($this->creates === 0) { + $this->creates = Timer::tick(10000, [$this, 'Heartbeat_detection']); + } return $client; }