Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ PHP NEWS
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a
persistent connection. (Ilia Alshanetsky)

- PDO_DBLIB:
. Fixed a crash on persistent connections after an error raised through
PDO::exec(). (Ilia Alshanetsky)

- PDO_Firebird:
. Fixed bug GH-25006 (getColumnMeta() reads out of bounds for an
out-of-range column index). (Ilia Alshanetsky)
Expand Down
11 changes: 10 additions & 1 deletion ext/pdo_dblib/dblib_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ static void dblib_handle_closer(pdo_dbh_t *dbh)
}
}

static void dblib_handle_request_shutdown(pdo_dbh_t *dbh)
{
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;

if (H && dbh->refcount <= 2) {
pdo_dblib_err_dtor(&H->err);
}
}

static bool dblib_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options)
{
pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;
Expand Down Expand Up @@ -450,7 +459,7 @@ static const struct pdo_dbh_methods dblib_methods = {
dblib_get_attribute, /* get attr */
NULL, /* check liveness */
NULL, /* get driver methods */
NULL, /* request shutdown */
dblib_handle_request_shutdown,
NULL, /* in transaction, use PDO's internal tracking mechanism */
NULL, /* get gc */
NULL /* scanner */
Expand Down
44 changes: 44 additions & 0 deletions ext/pdo_dblib/tests/persistent_error_state_across_requests.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
PDO_DBLIB: Persistent handle error state does not outlive the request
--EXTENSIONS--
pdo_dblib
--SKIPIF--
<?php
require __DIR__ . '/config.inc';
getDbConnection();
?>
--ENV--
USE_ZEND_ALLOC=0
USE_TRACKED_ALLOC=1
--FILE--
<?php
require __DIR__ . '/../../../sapi/cli/tests/php_cli_server.inc';

$code = sprintf(<<<'PHP'
require %s;
[$dsn, $user, $pass] = getCredentials();
$db = new PDO($dsn, $user, $pass, [PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]);
$stmt = $db->prepare('SELECT 1');
$stmt->execute();
var_dump($stmt->fetchColumn());
$db->exec('SELECT * FROM ' . $_GET['table']);
echo $db->errorInfo()[2], "\n";
PHP, var_export(__DIR__ . '/config.inc', true));

$args = [];
foreach (['pdo', 'pdo_dblib'] as $ext) {
if (file_exists(ini_get('extension_dir') . '/' . $ext . '.' . PHP_SHLIB_SUFFIX)) {
$args[] = '-dextension=' . ini_get('extension_dir') . '/' . $ext . '.' . PHP_SHLIB_SUFFIX;
}
}
php_cli_server_start($code, null, $args);

foreach (['pdo_dblib_missing_first', 'pdo_dblib_missing_second'] as $table) {
echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/index.php?table=' . $table);
}
?>
--EXPECTF--
int(1)
Invalid object name 'pdo_dblib_missing_first'. [%d] (severity %d) []
int(1)
Invalid object name 'pdo_dblib_missing_second'. [%d] (severity %d) []
Loading