From adffcf18528927388967acad2ed94935e4fca659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 13 Feb 2023 14:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Pool/Connection.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kiri-engine/Pool/Connection.php b/kiri-engine/Pool/Connection.php index 77eef671..dd3680fb 100644 --- a/kiri-engine/Pool/Connection.php +++ b/kiri-engine/Pool/Connection.php @@ -100,7 +100,11 @@ class Connection extends Component if (!$this->pool->hasChannel($name)) { $this->pool->initConnections($name, $config['pool']['max']); } - return $this->pool->get($name, $this->generate($config)); + if (!Context::hasContext($name)) { + return Context::setContext($name, $this->pool->get($name, $this->generate($config))); + } else { + return Context::getContext($name); + } } @@ -111,6 +115,8 @@ class Connection extends Component public function generate(array $config): Closure { return static function () use ($config) { + Kiri::getDi()->get(Kiri\Error\StdoutLoggerInterface::class)->alert('create database connect(' . $config['cds'] . ')'); + $link = new \PDO('mysql:dbname=' . $config['dbname'] . ';host=' . $config['cds'], $config['username'], $config['password'], [ \PDO::ATTR_EMULATE_PREPARES => false, \PDO::ATTR_CASE => \PDO::CASE_NATURAL, @@ -165,6 +171,9 @@ class Connection extends Component public function addItem(string $name, PDO $PDO): void { $this->pool->push($name, $PDO); + if (Context::inCoroutine()) { + Context::remove($name); + } }