From 4bd7b43c8663d11a509641ff0ee1c8ea77a30208 Mon Sep 17 00:00:00 2001 From: jdarwood007 Date: Sat, 25 Nov 2023 09:03:57 -0800 Subject: [PATCH] Adjust the logic to exit the construct early if we don't have a connection --- Sources/Db/APIs/MySQL.php | 16 ++++++++++------ Sources/Db/APIs/PostgreSQL.php | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Sources/Db/APIs/MySQL.php b/Sources/Db/APIs/MySQL.php index 36d2c38d9f..60b56f089d 100644 --- a/Sources/Db/APIs/MySQL.php +++ b/Sources/Db/APIs/MySQL.php @@ -1984,20 +1984,24 @@ protected function __construct(array $options = []) $this->prefixReservedTables(); } - if (empty($this->connection) && !$non_fatal) { - $this->get_version(); - $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); - } - // For backward compatibility. if (!is_object(self::$db_connection)) { self::$db_connection = $this->connection; } + // At this point, if we don't have a connection, nothing else can be done. + if (empty($this->connection)) { + return; + } + + $this->get_version(); + $this->supports_pcre = version_compare($this->version, strpos($this->version, 'MariaDB') !== false ? '10.0.5' : '8.0.4', '>='); + // Ensure database has UTF-8 as its default input charset. $this->query( '', - 'SET NAMES {string:db_character_set}', + ' + SET NAMES {string:db_character_set}', [ 'db_character_set' => $this->character_set, ], diff --git a/Sources/Db/APIs/PostgreSQL.php b/Sources/Db/APIs/PostgreSQL.php index 3d5493c690..cf76afa618 100644 --- a/Sources/Db/APIs/PostgreSQL.php +++ b/Sources/Db/APIs/PostgreSQL.php @@ -2117,6 +2117,11 @@ protected function __construct(array $options = []) self::$db_connection = $this->connection; } + // At this point, if we don't have a connection, nothing else can be done. + if (empty($this->connection)) { + return; + } + // Ensure database has UTF-8 as its default input charset. $this->query( '',