Mysql try ... catch

This commit is contained in:
Alexander Pankratov 2020-05-12 01:41:27 +03:00
parent 8254360d2f
commit 912577617e
2 changed files with 14 additions and 9 deletions

View File

@ -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,6 +63,7 @@ class Mysql
private static function createDb(ConnectionConfig $config)
{
wait(call(static function() use($config) {
try {
$db = $config->getDatabase();
$connection = pool($config->withDatabase(null));
yield $connection->query("
@ -70,6 +72,9 @@ class Mysql
COLLATE 'utf8mb4_general_ci'
");
$connection->close();
} catch (\Throwable $e) {
Logger::log($e->getMessage(), Logger::ERROR);
}
}));
}

View File

@ -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 [];
}