2017-05-04 02:00:31 +03:00
|
|
|
--TEST--
|
|
|
|
Connection Close Test
|
|
|
|
--DESCRIPTION--
|
|
|
|
Verifies that a connection can be closed multiple times and
|
|
|
|
that resources are invalidated when connection is closed.
|
|
|
|
--ENV--
|
|
|
|
PHPT_EXEC=true
|
|
|
|
--SKIPIF--
|
2017-10-24 03:04:35 +03:00
|
|
|
<?php require('skipif_versions_old.inc'); ?>
|
2017-05-04 02:00:31 +03:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2017-10-05 00:22:56 +03:00
|
|
|
require_once('MsCommon.inc');
|
2017-05-04 02:00:31 +03:00
|
|
|
|
2020-07-09 05:45:00 +03:00
|
|
|
// When testing with PHP 8.0 it throws a TypeError instead of a warning. Thus implement a custom
|
|
|
|
// warning handler such that with PHP 7.x the warning would be handled to throw a TypeError.
|
|
|
|
function warningHandler($errno, $errstr)
|
|
|
|
{
|
|
|
|
throw new TypeError($errstr);
|
|
|
|
}
|
|
|
|
|
2017-10-24 03:04:35 +03:00
|
|
|
function connectionClose()
|
2017-05-04 02:00:31 +03:00
|
|
|
{
|
|
|
|
$testName = "Connection - Close";
|
2017-10-05 00:22:56 +03:00
|
|
|
startTest($testName);
|
|
|
|
setup();
|
2017-10-24 03:04:35 +03:00
|
|
|
$conn1 = AE\connect();
|
|
|
|
$tableName = 'TC24test';
|
2017-10-05 00:22:56 +03:00
|
|
|
|
2017-10-26 20:48:36 +03:00
|
|
|
// Insert some random rows
|
2017-10-24 03:04:35 +03:00
|
|
|
AE\createTestTable($conn1, $tableName);
|
2017-10-26 20:48:36 +03:00
|
|
|
AE\insertTestRows($conn1, $tableName, 5);
|
2017-05-04 02:00:31 +03:00
|
|
|
|
2020-07-09 05:45:00 +03:00
|
|
|
try {
|
|
|
|
// Close connection twice
|
|
|
|
for ($i = 0; $i < 2; $i++) {
|
|
|
|
$ret = sqlsrv_close($conn1);
|
|
|
|
if ($ret === false) {
|
|
|
|
die("Unexpected return for sqlsrv_close: $ret");
|
|
|
|
}
|
2017-05-04 02:00:31 +03:00
|
|
|
}
|
2020-07-09 05:45:00 +03:00
|
|
|
} catch (TypeError $e) {
|
|
|
|
echo $e->getMessage() . PHP_EOL;
|
2017-05-04 02:00:31 +03:00
|
|
|
}
|
2017-10-05 00:22:56 +03:00
|
|
|
|
2020-07-09 05:45:00 +03:00
|
|
|
try {
|
|
|
|
// Invalid Query
|
|
|
|
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM [$tableName]");
|
|
|
|
if ($stmt1) {
|
|
|
|
die("Select query should fail when connection is closed");
|
|
|
|
}
|
|
|
|
} catch (TypeError $e) {
|
|
|
|
echo $e->getMessage() . PHP_EOL;
|
2017-05-04 02:00:31 +03:00
|
|
|
}
|
|
|
|
|
2020-07-09 05:45:00 +03:00
|
|
|
try {
|
|
|
|
// Invalid Statement
|
|
|
|
$conn2 = AE\connect();
|
|
|
|
$stmt2 = AE\selectFromTable($conn2, $tableName);
|
|
|
|
sqlsrv_close($conn2);
|
|
|
|
if (sqlsrv_fetch($stmt2)) {
|
|
|
|
die("Fetch should fail when connection is closed");
|
|
|
|
}
|
|
|
|
} catch (TypeError $e) {
|
|
|
|
echo $e->getMessage() . PHP_EOL;
|
2017-05-04 02:00:31 +03:00
|
|
|
}
|
2017-10-05 00:22:56 +03:00
|
|
|
|
2017-10-24 03:04:35 +03:00
|
|
|
$conn3 = AE\connect();
|
|
|
|
dropTable($conn3, $tableName);
|
|
|
|
sqlsrv_close($conn3);
|
2017-05-04 02:00:31 +03:00
|
|
|
|
2017-10-05 00:22:56 +03:00
|
|
|
endTest($testName);
|
2017-05-04 02:00:31 +03:00
|
|
|
}
|
|
|
|
|
2017-10-24 03:04:35 +03:00
|
|
|
try {
|
2020-07-09 05:45:00 +03:00
|
|
|
set_error_handler("warningHandler", E_WARNING);
|
2017-10-24 03:04:35 +03:00
|
|
|
connectionClose();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo $e->getMessage();
|
2017-05-04 02:00:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
2020-07-09 05:45:00 +03:00
|
|
|
--EXPECT--
|
|
|
|
sqlsrv_close(): supplied resource is not a valid ss_sqlsrv_conn resource
|
|
|
|
sqlsrv_query(): supplied resource is not a valid ss_sqlsrv_conn resource
|
|
|
|
sqlsrv_fetch(): supplied resource is not a valid ss_sqlsrv_stmt resource
|
2017-05-04 02:00:31 +03:00
|
|
|
Test "Connection - Close" completed successfully.
|