From d036e440cd5fd30aa54316d1aff427d0d0b85e17 Mon Sep 17 00:00:00 2001 From: whwyy Date: Wed, 10 Jan 2024 17:43:10 +0800 Subject: [PATCH] eee --- Command.php | 2 ++ Connection.php | 52 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Command.php b/Command.php index 26b282b..3f58e49 100644 --- a/Command.php +++ b/Command.php @@ -117,6 +117,7 @@ class Command extends Component { $client = $this->connection->getConnection(); try { + $this->connection->println($this->sql, $this->params); if (($prepare = $client->prepare($this->sql)) === false) { throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $client->errorInfo()[2]); } @@ -157,6 +158,7 @@ class Command extends Component { $client = $this->connection->getConnection(); try { + $this->connection->println($this->sql, $this->params); if (($prepare = $client->prepare($this->sql)) === false) { throw new Exception('(' . $prepare->errorInfo()[0] . ')' . $prepare->errorInfo()[2]); } diff --git a/Connection.php b/Connection.php index ffeb762..e911cd0 100644 --- a/Connection.php +++ b/Connection.php @@ -37,24 +37,25 @@ use Swoole\Timer; class Connection extends Component { - public string $id = 'db'; - public string $cds = ''; - public string $password = ''; - public string $username = ''; - public string $charset = 'utf-8'; - public string $tablePrefix = ''; - public string $database = ''; - public int $timeout = 30; - public int $waite_time = 3; - public int $tick_time = 60; - public int $idle_count = 3; - public int $idle_time = 60; - public array $pool = ['max' => 10, 'min' => 1]; - private int $storey = 0; - protected int $timerId = -1; - public bool $enableCache = false; - public string $cacheDriver = 'redis'; - public array $attributes = []; + public string $id = 'db'; + public string $cds = ''; + public string $password = ''; + public string $username = ''; + public string $charset = 'utf-8'; + public string $tablePrefix = ''; + public string $database = ''; + public int $timeout = 30; + public int $waite_time = 3; + public int $tick_time = 60; + public int $idle_count = 3; + public int $idle_time = 60; + public array $pool = ['max' => 10, 'min' => 1]; + private int $storey = 0; + protected int $timerId = -1; + public bool $enableCache = false; + public string $cacheDriver = 'redis'; + public array $attributes = []; + protected \Closure $_println; /** @@ -69,6 +70,21 @@ class Connection extends Component public function __construct(public Pool $connections) { parent::__construct(); + + $this->_println = \config('databases.logger', null); + } + + + /** + * @param string $sql + * @param array $params + * @return void + */ + public function println(string $sql, array $params = []): void + { + if (is_callable($this->_println)) { + call_user_func($this->_println, $sql, $params); + } }