From 255f703f37f79cde3b78f804c63957df8f6bc900 Mon Sep 17 00:00:00 2001 From: wakqasahmed Date: Sat, 19 Sep 2026 20:30:56 +0200 Subject: [PATCH 1/3] fix: throw Postgre query errors with warnings disabled (#6913) --- system/Database/Postgre/Connection.php | 8 +++++++- tests/system/Database/Live/BadQueryTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index a152b90aa539..037e3b2f58a4 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -207,7 +207,13 @@ public function getVersion(): string protected function execute(string $sql) { try { - return pg_query($this->connID, $sql); + $result = pg_query($this->connID, $sql); + + if ($result === false && $this->DBDebug) { + throw new DatabaseException((string) pg_last_error($this->connID)); + } + + return $result; } catch (ErrorException $e) { $trace = array_slice($e->getTrace(), 2); // remove the call to error handler diff --git a/tests/system/Database/Live/BadQueryTest.php b/tests/system/Database/Live/BadQueryTest.php index 8b842b21b930..587cabc3bdec 100644 --- a/tests/system/Database/Live/BadQueryTest.php +++ b/tests/system/Database/Live/BadQueryTest.php @@ -53,4 +53,22 @@ public function testBadQueryDebugFalse(): void $this->enableDBDebug(); } + + public function testPostgreBadQueryDebugTrueWithWarningsDisabled(): void + { + if ($this->db->DBDriver !== 'Postgre') { + $this->markTestSkipped('This test is only for Postgre.'); + } + + $this->enableDBDebug(); + $errorReporting = error_reporting(E_ALL & ~E_WARNING); + + try { + $this->expectException(DatabaseException::class); + $this->expectExceptionMessage('table_does_not_exist'); + $this->db->query('SELECT * FROM table_does_not_exist'); + } finally { + error_reporting($errorReporting); + } + } } From 2825ce07b16d41b15ea16f6d0eed36dea8031ced Mon Sep 17 00:00:00 2001 From: wakqasahmed Date: Sat, 19 Sep 2026 20:39:29 +0200 Subject: [PATCH 2/3] style: satisfy Rector for Postgre errors (#6913) --- system/Database/Postgre/Connection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 037e3b2f58a4..6f6233d14b74 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -210,7 +210,7 @@ protected function execute(string $sql) $result = pg_query($this->connID, $sql); if ($result === false && $this->DBDebug) { - throw new DatabaseException((string) pg_last_error($this->connID)); + throw new DatabaseException(pg_last_error($this->connID)); } return $result; From 2382e288301b42efa5f60541b004b1d07b15669a Mon Sep 17 00:00:00 2001 From: wakqasahmed Date: Fri, 25 Sep 2026 22:32:44 +0200 Subject: [PATCH 3/3] docs: add changelog entry for Postgre query errors (#6913) --- user_guide_src/source/changelogs/v4.7.5.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelogs/v4.7.5.rst b/user_guide_src/source/changelogs/v4.7.5.rst index 5fc0cfce5578..34f3257c5d7a 100644 --- a/user_guide_src/source/changelogs/v4.7.5.rst +++ b/user_guide_src/source/changelogs/v4.7.5.rst @@ -53,6 +53,7 @@ Bugs Fixed - **Cookie:** Fixed a bug where ``Cookie`` instances created with ``raw: true`` allowed invalid characters in cookie values rejected by ``setrawcookie()``. - **Cookie:** Fixed a bug where ``Cookie`` instances allowed invalid characters in path, domain, and prefix attributes rejected by ``setcookie()`` and ``setrawcookie()``. - **Database:** Fixed a bug where rebuilding a SQLite3 table (e.g., ``Forge::dropColumn()``, ``Forge::modifyColumn()``, ``Forge::dropForeignKey()`` and ``Forge::dropPrimaryKey()``) corrupted the table names referenced by its foreign keys when ``DBPrefix`` was set. +- **Database:** Fixed a bug where Postgre query failures were silently ignored when ``DBDebug`` was enabled and PHP warnings were disabled. A ``DatabaseException`` is now thrown. - **Debug:** Fixed a bug where ``Timer::start()`` treated ``0.0`` as an empty value and substituted the current time. - **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``. - **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.