[php-src] master: Honor ERRMODE_SILENT in pdo_raise_impl_error (#23070)

From: Date: Mon, 10 Aug 2026 12:10:05 +0000
Subject: [php-src] master: Honor ERRMODE_SILENT in pdo_raise_impl_error (#23070)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-140586@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Committer: GitHub (web-flow) Pusher: iliaal Date: 2026-08-10T08:10:02-04:00 Commit: https://github.com/php/php-src/commit/8f2d79e4d15d31d3dead77d5a637e5c56ad4be1d Raw diff: https://github.com/php/php-src/commit/8f2d79e4d15d31d3dead77d5a637e5c56ad4be1d.diff Honor ERRMODE_SILENT in pdo_raise_impl_error (#23070) pdo_raise_impl_error stored the SQLSTATE then still emitted E_WARNING even when the handle error mode was SILENT. The early return for SILENT was present but disabled (#if 0). Copy the error code first so errorInfo() remains valid, then return without warning. Closes GH-23070 Changed paths: A ext/pdo_sqlite/tests/pdo_silent_impl_error.phpt M NEWS M ext/pdo/pdo_dbh.c Diff: diff --git a/NEWS b/NEWS index ae9a19c0cc87..2a06febbfa28 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,10 @@ PHP NEWS . Added SpoofChecker::getBidiSkeleton(). (Weilin Du) . Added SpoofChecker::getSkeleton(). (David Carlier) +- PDO: + . Fixed pdo_raise_impl_error() emitting a warning under ERRMODE_SILENT. + (iliaal) + - PDO_ODBC: . Fixed bug GH-23016 (NULL values in long columns come back as garbage binary strings). (Calvin Buckley, iliaal) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index dcd9f7b126df..b7e2887e03eb 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -73,21 +73,16 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, pdo_error_type sqlst pdo_error_type *pdo_err = &dbh->error_code; const char *msg; - if (dbh->error_mode == PDO_ERRMODE_SILENT) { -#if 0 - /* BUG: if user is running in silent mode and hits an error at the driver level - * when they use the PDO methods to call up the error information, they may - * get bogus information */ - return; -#endif - } - if (stmt) { pdo_err = &stmt->error_code; } memcpy(*pdo_err, sqlstate, sizeof(pdo_error_type)); + if (dbh->error_mode == PDO_ERRMODE_SILENT) { + return; + } + /* hash sqlstate to error messages */ msg = pdo_sqlstate_state_to_description(*pdo_err); if (!msg) { diff --git a/ext/pdo_sqlite/tests/pdo_silent_impl_error.phpt b/ext/pdo_sqlite/tests/pdo_silent_impl_error.phpt new file mode 100644 index 000000000000..762c8848b8b6 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_silent_impl_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +pdo_raise_impl_error honors ERRMODE_SILENT (no warning) +--EXTENSIONS-- +pdo_sqlite +--FILE-- +<?php +$pdo = new PDO('sqlite::memory:'); +$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); +set_error_handler(function (int $errno, string $errstr): bool { + echo "warning: $errstr\n"; + return true; +}); +$result = $pdo->getAttribute(123456); +echo "result: "; +var_dump($result); +echo "errorInfo: "; +var_dump($pdo->errorInfo()[0]); +?> +--EXPECT-- +result: bool(false) +errorInfo: string(5) "IM001"

« previous php.cvs (#140586) next »