mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
[pdo_firebird] Added pdo_firebird_check_liveness handler (#12757)
This commit is contained in:
parent
927adfb1a6
commit
5dfb2d95ea
3 changed files with 66 additions and 1 deletions
|
@ -231,6 +231,8 @@ PHP 8.4 UPGRADE NOTES
|
|||
Along with these, five constants (PDO::FB_TRANSACTION_ISOLATION_LEVEL,
|
||||
PDO::FB_READ_COMMITTED, PDO::FB_REPEATABLE_READ, PDO::FB_SERIALIZABLE,
|
||||
PDO::FB_WRITABLE_TRANSACTION) have been added.
|
||||
. When using persistent connections, there is now a liveness check in the
|
||||
constructor.
|
||||
|
||||
- PDO_MYSQL:
|
||||
. getAttribute, enabled to get the value of ATTR_FETCH_TABLE_NAMES.
|
||||
|
|
|
@ -1216,6 +1216,18 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
#if FB_API_VER >= 30
|
||||
/* called by PDO to check liveness */
|
||||
static zend_result pdo_firebird_check_liveness(pdo_dbh_t *dbh) /* {{{ */
|
||||
{
|
||||
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
|
||||
|
||||
/* fb_ping return 0 if the connection is alive */
|
||||
return fb_ping(H->isc_status, &H->db) ? FAILURE : SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
/* called by PDO to retrieve driver-specific information about an error that has occurred */
|
||||
static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
|
||||
{
|
||||
|
@ -1254,7 +1266,11 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */
|
|||
NULL, /* last_id not supported */
|
||||
pdo_firebird_fetch_error_func,
|
||||
pdo_firebird_get_attribute,
|
||||
NULL, /* check_liveness */
|
||||
#if FB_API_VER >= 30
|
||||
pdo_firebird_check_liveness,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
NULL, /* get driver methods */
|
||||
NULL, /* request shutdown */
|
||||
pdo_firebird_in_manually_transaction,
|
||||
|
|
47
ext/pdo_firebird/tests/persistent_connect.phpt
Normal file
47
ext/pdo_firebird/tests/persistent_connect.phpt
Normal file
|
@ -0,0 +1,47 @@
|
|||
--TEST--
|
||||
PDO_Firebird: persistent connect test
|
||||
--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
|
||||
|
||||
/**
|
||||
* Omit the case where the connection is broken when it checks liveness and
|
||||
* it has to reconnect, as it is very difficult to reproduce the situation.
|
||||
*/
|
||||
|
||||
require("testdb.inc");
|
||||
unset($dbh);
|
||||
|
||||
$connIds = [];
|
||||
|
||||
foreach (['First', 'Second'] as $times) {
|
||||
$dbh = new PDO(
|
||||
PDO_FIREBIRD_TEST_DSN,
|
||||
PDO_FIREBIRD_TEST_USER,
|
||||
PDO_FIREBIRD_TEST_PASS,
|
||||
[
|
||||
PDO::ATTR_PERSISTENT => true,
|
||||
],
|
||||
);
|
||||
$stmt = $dbh->query('SELECT CURRENT_CONNECTION FROM RDB$DATABASE');
|
||||
$connId = $stmt->fetchColumn();
|
||||
$connIds[] = $connId;
|
||||
echo "{$times} connection ID: {$connId}\n";
|
||||
|
||||
unset($dbh);
|
||||
unset($stmt);
|
||||
unset($connID);
|
||||
}
|
||||
|
||||
echo $connIds[0] === $connIds[1] ? "Same ID.\n" : "Different ID\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
First connection ID: %d
|
||||
Second connection ID: %d
|
||||
Same ID.
|
Loading…
Add table
Add a link
Reference in a new issue