From 912577617ec76a0a69330d8612b619d6d18c9729 Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Tue, 12 May 2020 01:41:27 +0300 Subject: [PATCH] Mysql try ... catch --- src/danog/MadelineProto/Db/Mysql.php | 21 +++++++++++++-------- src/danog/MadelineProto/Db/MysqlArray.php | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/danog/MadelineProto/Db/Mysql.php b/src/danog/MadelineProto/Db/Mysql.php index 593a94ab..75d5618e 100644 --- a/src/danog/MadelineProto/Db/Mysql.php +++ b/src/danog/MadelineProto/Db/Mysql.php @@ -5,6 +5,7 @@ namespace danog\MadelineProto\Db; use Amp\Mysql\ConnectionConfig; use Amp\Mysql\Pool; use Amp\Sql\Common\ConnectionPool; +use danog\MadelineProto\Logger; use function Amp\call; use function Amp\Mysql\Pool; use function Amp\Promise\wait; @@ -62,14 +63,18 @@ class Mysql private static function createDb(ConnectionConfig $config) { wait(call(static function() use($config) { - $db = $config->getDatabase(); - $connection = pool($config->withDatabase(null)); - yield $connection->query(" - CREATE DATABASE IF NOT EXISTS `{$db}` - CHARACTER SET 'utf8mb4' - COLLATE 'utf8mb4_general_ci' - "); - $connection->close(); + try { + $db = $config->getDatabase(); + $connection = pool($config->withDatabase(null)); + yield $connection->query(" + CREATE DATABASE IF NOT EXISTS `{$db}` + CHARACTER SET 'utf8mb4' + COLLATE 'utf8mb4_general_ci' + "); + $connection->close(); + } catch (\Throwable $e) { + Logger::log($e->getMessage(), Logger::ERROR); + } })); } diff --git a/src/danog/MadelineProto/Db/MysqlArray.php b/src/danog/MadelineProto/Db/MysqlArray.php index 06db3c84..6452629f 100644 --- a/src/danog/MadelineProto/Db/MysqlArray.php +++ b/src/danog/MadelineProto/Db/MysqlArray.php @@ -320,7 +320,7 @@ class MysqlArray implements DbArray try { $request = yield $this->db->execute($query, $params); } catch (\Throwable $e) { - Logger::log($e, Logger::ERROR); + Logger::log($e->getMessage(), Logger::ERROR); return []; }