Fixed GH-17383 - pdo_firebird: PDOException has wrong code and message since PHP 8.4 (#18072)

Closes #18072
Fixes #17383
This commit is contained in:
Saki Takamachi 2025-04-19 14:11:20 +09:00
parent ce7304f909
commit 685baf77df
No known key found for this signature in database
GPG key ID: 770426E17EBBB3DD
4 changed files with 48 additions and 4 deletions

View file

@ -58,12 +58,15 @@ if "%PLATFORM%" == "x64" (
curl -sLo Firebird.zip %PHP_FIREBIRD_DOWNLOAD_URL%
7z x -oC:\Firebird Firebird.zip
set PDO_FIREBIRD_TEST_DATABASE=C:\test.fdb
set PDO_FIREBIRD_TEST_DSN=firebird:dbname=%PDO_FIREBIRD_TEST_DATABASE%
set PDO_FIREBIRD_TEST_DSN=firebird:dbname=127.0.0.1:%PDO_FIREBIRD_TEST_DATABASE%
set PDO_FIREBIRD_TEST_USER=SYSDBA
set PDO_FIREBIRD_TEST_PASS=phpfi
echo create user %PDO_FIREBIRD_TEST_USER% password '%PDO_FIREBIRD_TEST_PASS%';> C:\Firebird\create_user.sql
echo commit;>> C:\Firebird\create_user.sql
echo create database '%PDO_FIREBIRD_TEST_DATABASE%' user '%PDO_FIREBIRD_TEST_USER%' password '%PDO_FIREBIRD_TEST_PASS%';> C:\Firebird\setup.sql
C:\Firebird\instsvc.exe install -n TestInstance
C:\Firebird\isql -q -i C:\Firebird\setup.sql
C:\Firebird\isql -q -i C:\Firebird\create_user.sql -user sysdba %PDO_FIREBIRD_TEST_DATABASE%
C:\Firebird\instsvc.exe start -n TestInstance
if %errorlevel% neq 0 exit /b 3
path C:\Firebird;%PATH%

6
NEWS
View file

@ -42,8 +42,10 @@ PHP NEWS
. Fix potential leaks when writing to BIO fails. (nielsdos)
- PDO Firebird:
. Fixed GH-18276 - persistent connection - "zend_mm_heap corrupted"
with setAttribute() (SakiTakamachi).
. Fixed bug GH-18276 (persistent connection - "zend_mm_heap corrupted"
with setAttribute()) (SakiTakamachi).
. Fixed bug GH-17383 (PDOException has wrong code and message since PHP 8.4)
(SakiTakamachi).
- PDO Sqlite:
. Fix memory leak on error return of collation callback. (nielsdos)

View file

@ -594,7 +594,8 @@ static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
}
H->in_manually_txn = 0;
if (isc_detach_database(H->isc_status, &H->db)) {
/* isc_detach_database returns 0 on success, 1 on failure. */
if (H->db && isc_detach_database(H->isc_status, &H->db)) {
php_firebird_error(dbh);
}

View file

@ -0,0 +1,38 @@
--TEST--
GH-17383 (PDOException has wrong code and message since PHP 8.4)
--EXTENSIONS--
pdo_firebird
--SKIPIF--
<?php require('skipif.inc'); ?>
--XLEAK--
A bug in firebird causes a memory leak when calling `isc_attach_database()`.
See https://github.com/FirebirdSQL/firebird/issues/7849
--FILE--
<?php
require("testdb.inc");
unset($dbh);
foreach ([
['firebird:dbname=invalid_host:db', PDO_FIREBIRD_TEST_USER, PDO_FIREBIRD_TEST_PASS],
[PDO_FIREBIRD_TEST_DSN, 'invalid_user', PDO_FIREBIRD_TEST_PASS],
[PDO_FIREBIRD_TEST_DSN, PDO_FIREBIRD_TEST_USER, 'invalid_pass'],
] as [$dsn, $user, $pass]) {
try {
$dbh = new PDO($dsn, $user, $pass);
} catch (PDOException $e) {
echo 'PDOException code: ' . $e->getCode() . "\n";
echo 'PDOException message: ' . $e->getMessage() . "\n";
echo "\n";
}
}
?>
--EXPECT--
PDOException code: 335544721
PDOException message: SQLSTATE[HY000] [335544721] Unable to complete network request to host "invalid_host".
PDOException code: 335544472
PDOException message: SQLSTATE[HY000] [335544472] Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
PDOException code: 335544472
PDOException message: SQLSTATE[HY000] [335544472] Your user name and password are not defined. Ask your database administrator to set up a Firebird login.