Open haanerg opened 2 years ago
So it looks like if ibase_close is called without arguments, only the latest resource (default_link) will be closed, after which any further calls to ibase_close without arguments will result in the function returning false. https://github.com/FirebirdSQL/php-firebird/blob/master/interbase.c#L1060
Whenever ibase_close is called with a connection, the function will always return true.
We end up having problems because of the behavior of ibase_close. (The behaviour is not the same in previous versions - we tested it in PHP 7.0).
Our test does the following:
$connection = ibase_connect($database, $username, $password);
//INITIAL SELECT
$stmt = ibase_prepare($connection, "SELECT ARRANGOR_ID FROM \"EVENT\" WHERE EVENT_NO = ?");
$res = ibase_execute($stmt, $eventNo);
$data = ibase_fetch_assoc($res);
echo "PRE UPDATE\n";
var_dump($data);
ibase_free_result($res);
ibase_free_query($stmt);
//TRANSACTION UDPATE AND SELECT
IBASE_DEFAULT;
$transaction = ibase_trans(IBASE_DEFAULT, $connection);
$stmt = ibase_prepare($connection, $transaction, "UPDATE \"EVENT\" SET ARRANGOR_ID = ? WHERE EVENT_NO = ?");
ibase_execute($stmt, $newID, $eventNo);
ibase_free_query($stmt);
$stmt = ibase_prepare($connection, $transaction, "SELECT ARRANGOR_ID FROM \"EVENT\" WHERE EVENT_NO = ?");
$res = ibase_execute($stmt, $eventNo);
$data = ibase_fetch_assoc($res);
ibase_free_result($res);
ibase_free_query($stmt);
echo "IN TRANSACTION\n";
var_dump($data);
ibase_commit($transaction);
//AFTER TRANSACTION
$stmt = ibase_prepare($connection, "SELECT ARRANGOR_ID FROM \"EVENT\" WHERE EVENT_NO = ?");
$res = ibase_execute($stmt, $eventNo);
$data = ibase_fetch_assoc($res);
ibase_free_result($res);
ibase_free_query($stmt);
echo "AFTER TRANSACTION\n";
var_dump($data);
//CLOSE CONNECTION
// ibase_close();
ibase_close($connection);
// TEST CLOSED CONNECTION WORKING
$stmt = ibase_prepare($connection, "SELECT ARRANGOR_ID FROM \"EVENT\" WHERE EVENT_NO = ?");
$res = ibase_execute($stmt, $eventNo);
$data = ibase_fetch_assoc($res);
ibase_free_result($res);
echo "AFTER CLOSE\n";
var_dump($data);
$newConnection = ibase_connect($database, $username, $password);
//AFTER RECONNECT
$stmt = ibase_prepare($newConnection, "SELECT ARRANGOR_ID FROM \"EVENT\" WHERE EVENT_NO = ?");
$res = ibase_execute($stmt, $eventNo);
$data = ibase_fetch_assoc($res);
echo "AFTER RECONNECT \n";
var_dump($data);
ibase_free_result($res);
//SELECT IN NEW TRANSACTION
$transaction = ibase_trans(IBASE_DEFAULT, $newConnection);
$stmt = ibase_prepare($newConnection, $transaction, "SELECT ARRANGOR_ID FROM \"EVENT\" WHERE EVENT_NO = ?");
$res = ibase_execute($stmt, $eventNo);
$data = ibase_fetch_assoc($res);
ibase_free_result($res);
echo "IN NEW TRANSACTION\n";
var_dump($data);
ibase_commit($transaction);
It looks like ibase_close noes not work as expected, at least if the docs are to be believed. Closing a connection doesn't work for us with PHP7.4.3 and version 1.1.1 of the driver. Other combinations tested yields the same result. There also seems to be a mismatch between the docs and the test case (ibase_close_001.phpt).
If we have a look at the test case:
If the connection ($x) is truly closed, the second and third call to ibase_close should return false. However, it seems like calling ibase_close($x) does not close the connection. Calling ibase_close() without a resource seems to close all connections, which is ok but not documented.