added skipifs to connres and aad tests
This commit is contained in:
parent
329fa3409e
commit
9fc7e4bf4b
|
@ -1,98 +1,99 @@
|
|||
--TEST--
|
||||
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsSetup.inc");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with Authentication=SqlPassword.
|
||||
//
|
||||
$connectionInfo = "Database = $databaseName; Authentication = SqlPassword; TrustServerCertificate = true;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully with Authentication=SqlPassword.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect with Authentication=SqlPassword.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$stmt = $conn->query( "SELECT count(*) FROM cd_info" );
|
||||
if ( $stmt === false )
|
||||
{
|
||||
echo "Query failed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $stmt->fetch();
|
||||
var_dump( $result );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with integrated authentication. This should fail because
|
||||
// we don't support it.
|
||||
//
|
||||
$connectionInfo = "Authentication = ActiveDirectoryIntegrated; TrustServerCertificate = true;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo" );
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
|
||||
// your credentials to test, or this part is skipped.
|
||||
//
|
||||
$azureServer = $adServer;
|
||||
$azureDatabase = $adDatabase;
|
||||
$azureUsername = $adUser;
|
||||
$azurePassword = $adPassword;
|
||||
|
||||
if ($azureServer != 'TARGET_AD_SERVER')
|
||||
{
|
||||
$connectionInfo = "Authentication = ActiveDirectoryPassword; TrustServerCertificate = false";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $azureServer ; $connectionInfo", $azureUsername, $azurePassword );
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect with ActiveDirectoryPassword.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Connected successfully with Authentication=SqlPassword.
|
||||
array(2) {
|
||||
[""]=>
|
||||
string(1) "7"
|
||||
[0]=>
|
||||
string(1) "7"
|
||||
}
|
||||
Could not connect with Authentication=ActiveDirectoryIntegrated.
|
||||
SQLSTATE[IMSSP]: Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
|
||||
%s with Authentication=ActiveDirectoryPassword.
|
||||
--TEST--
|
||||
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc');
|
||||
require('skipif_version_not_2k16.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsSetup.inc");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with Authentication=SqlPassword.
|
||||
//
|
||||
$connectionInfo = "Database = $databaseName; Authentication = SqlPassword; TrustServerCertificate = true;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully with Authentication=SqlPassword.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect with Authentication=SqlPassword.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$stmt = $conn->query( "SELECT count(*) FROM cd_info" );
|
||||
if ( $stmt === false )
|
||||
{
|
||||
echo "Query failed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $stmt->fetch();
|
||||
var_dump( $result );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with integrated authentication. This should fail because
|
||||
// we don't support it.
|
||||
//
|
||||
$connectionInfo = "Authentication = ActiveDirectoryIntegrated; TrustServerCertificate = true;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; $connectionInfo" );
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
|
||||
// your credentials to test, or this part is skipped.
|
||||
//
|
||||
$azureServer = $adServer;
|
||||
$azureDatabase = $adDatabase;
|
||||
$azureUsername = $adUser;
|
||||
$azurePassword = $adPassword;
|
||||
|
||||
if ($azureServer != 'TARGET_AD_SERVER')
|
||||
{
|
||||
$connectionInfo = "Authentication = ActiveDirectoryPassword; TrustServerCertificate = false";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $azureServer ; $connectionInfo", $azureUsername, $azurePassword );
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect with ActiveDirectoryPassword.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Connected successfully with Authentication=SqlPassword.
|
||||
array(2) {
|
||||
[""]=>
|
||||
string(1) "7"
|
||||
[0]=>
|
||||
string(1) "7"
|
||||
}
|
||||
Could not connect with Authentication=ActiveDirectoryIntegrated.
|
||||
SQLSTATE[IMSSP]: Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
|
||||
%s with Authentication=ActiveDirectoryPassword.
|
||||
|
|
|
@ -1,248 +1,249 @@
|
|||
--TEST--
|
||||
Connection recovery test
|
||||
--DESCRIPTION--
|
||||
Connect and execute a command, kill the connection, execute another command.
|
||||
Then do it again without a buffered result set, by freeing the statement before
|
||||
killing the connection and then not freeing it. The latter case is the only one
|
||||
that should fail. Finally, execute two queries in two threads on a recovered
|
||||
non-MARS connection. This should fail too.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
// There is a lot of repeated code here that could be refactored with helper methods,
|
||||
// mostly for statement allocation. But that would affect scoping for the $stmt variables,
|
||||
// which could affect the results when attempting to reconnect. What happens to statements
|
||||
// when exiting the helper method? Do the associated cursors remain active? It is an
|
||||
// unnecessary complication, so I have left the code like this.
|
||||
|
||||
require_once( "break_pdo.php" );
|
||||
|
||||
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to successfully execute second query because buffered cursor for
|
||||
// first query means connection is idle when broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$query1 = "SELECT * FROM $tableName1";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt1 = $conn->prepare( $query1, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) );
|
||||
if ( $stmt1->execute() ) echo "Statement 1 successful.\n";
|
||||
|
||||
$rowcount = $stmt1->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$query2 = "SELECT * FROM $tableName2";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->prepare( $query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) );
|
||||
if ( $stmt2->execute() ) echo "Statement 2 successful.\n";
|
||||
|
||||
$rowcount = $stmt2->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 2.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to successfully execute second query because first statement is
|
||||
// freed before breaking connection
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$query1 = "SELECT * FROM $tableName1";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt3 = $conn->query( $query1 );
|
||||
if ( $stmt3 ) echo "Statement 3 successful.\n";
|
||||
|
||||
$rowcount = $stmt3->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 3.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$stmt3 = null;
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$query2 = "SELECT * FROM $tableName2";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt4 = $conn->query( $query2 );
|
||||
if ( $stmt4 ) echo "Statement 4 successful.\n";
|
||||
|
||||
$rowcount = $stmt4->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 4.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to fail executing second query because default cursor for first
|
||||
// query is still active when connection is broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$query1 = "SELECT * FROM $tableName1";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt5 = $conn->query( $query1 );
|
||||
if ( $stmt5 ) echo "Statement 5 successful.\n";
|
||||
|
||||
$rowcount = $stmt5->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 5.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$query2 = "SELECT * FROM $tableName2";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt6 = $conn->query( $query2 );
|
||||
if ( $stmt6 ) echo "Statement 6 successful.\n";
|
||||
|
||||
$rowcount = $stmt6->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 6.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 4
|
||||
// Expected to trigger an error because there are two active statements with
|
||||
// pending results and MARS is off
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10; MultipleActiveResultSets = false;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
$stmt7 = $conn->query( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt7 ) echo "Statement 7 successful.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 7.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$stmt8 = $conn->query( "SELECT * FROM $tableName2" );
|
||||
if ( $stmt8 ) echo "Statement 8 successful.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 8.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
$conn_break = null;
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 successful.
|
||||
16 rows in result set.
|
||||
Statement 2 successful.
|
||||
9 rows in result set.
|
||||
Statement 3 successful.
|
||||
-1 rows in result set.
|
||||
Statement 4 successful.
|
||||
-1 rows in result set.
|
||||
Statement 5 successful.
|
||||
-1 rows in result set.
|
||||
Error executing statement 6.
|
||||
SQLSTATE\[08S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
Statement 7 successful.
|
||||
Error executing statement 8.
|
||||
SQLSTATE\[IMSSP\]: The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option.
|
||||
--TEST--
|
||||
Connection recovery test
|
||||
--DESCRIPTION--
|
||||
Connect and execute a command, kill the connection, execute another command.
|
||||
Then do it again without a buffered result set, by freeing the statement before
|
||||
killing the connection and then not freeing it. The latter case is the only one
|
||||
that should fail. Finally, execute two queries in two threads on a recovered
|
||||
non-MARS connection. This should fail too.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
// There is a lot of repeated code here that could be refactored with helper methods,
|
||||
// mostly for statement allocation. But that would affect scoping for the $stmt variables,
|
||||
// which could affect the results when attempting to reconnect. What happens to statements
|
||||
// when exiting the helper method? Do the associated cursors remain active? It is an
|
||||
// unnecessary complication, so I have left the code like this.
|
||||
|
||||
require_once( "break_pdo.php" );
|
||||
|
||||
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to successfully execute second query because buffered cursor for
|
||||
// first query means connection is idle when broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$query1 = "SELECT * FROM $tableName1";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt1 = $conn->prepare( $query1, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) );
|
||||
if ( $stmt1->execute() ) echo "Statement 1 successful.\n";
|
||||
|
||||
$rowcount = $stmt1->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$query2 = "SELECT * FROM $tableName2";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->prepare( $query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) );
|
||||
if ( $stmt2->execute() ) echo "Statement 2 successful.\n";
|
||||
|
||||
$rowcount = $stmt2->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 2.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to successfully execute second query because first statement is
|
||||
// freed before breaking connection
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$query1 = "SELECT * FROM $tableName1";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt3 = $conn->query( $query1 );
|
||||
if ( $stmt3 ) echo "Statement 3 successful.\n";
|
||||
|
||||
$rowcount = $stmt3->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 3.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$stmt3 = null;
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$query2 = "SELECT * FROM $tableName2";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt4 = $conn->query( $query2 );
|
||||
if ( $stmt4 ) echo "Statement 4 successful.\n";
|
||||
|
||||
$rowcount = $stmt4->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 4.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to fail executing second query because default cursor for first
|
||||
// query is still active when connection is broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$query1 = "SELECT * FROM $tableName1";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt5 = $conn->query( $query1 );
|
||||
if ( $stmt5 ) echo "Statement 5 successful.\n";
|
||||
|
||||
$rowcount = $stmt5->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 5.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$query2 = "SELECT * FROM $tableName2";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt6 = $conn->query( $query2 );
|
||||
if ( $stmt6 ) echo "Statement 6 successful.\n";
|
||||
|
||||
$rowcount = $stmt6->rowCount();
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 6.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 4
|
||||
// Expected to trigger an error because there are two active statements with
|
||||
// pending results and MARS is off
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10; MultipleActiveResultSets = false;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
$stmt7 = $conn->query( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt7 ) echo "Statement 7 successful.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 7.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$stmt8 = $conn->query( "SELECT * FROM $tableName2" );
|
||||
if ( $stmt8 ) echo "Statement 8 successful.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 8.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
$conn_break = null;
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 successful.
|
||||
16 rows in result set.
|
||||
Statement 2 successful.
|
||||
9 rows in result set.
|
||||
Statement 3 successful.
|
||||
-1 rows in result set.
|
||||
Statement 4 successful.
|
||||
-1 rows in result set.
|
||||
Statement 5 successful.
|
||||
-1 rows in result set.
|
||||
Error executing statement 6.
|
||||
SQLSTATE\[08S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
Statement 7 successful.
|
||||
Error executing statement 8.
|
||||
SQLSTATE\[IMSSP\]: The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option.
|
||||
|
|
|
@ -1,84 +1,85 @@
|
|||
--TEST--
|
||||
Test the connection resiliency keywords ConnectRetryCount and ConnectRetryInterval and their ranges of acceptable values
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "MsSetup.inc" );
|
||||
|
||||
function TryToConnect( $retryCount, $retryInterval, $number )
|
||||
{
|
||||
global $server, $databaseName, $uid, $pwd;
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = $retryCount; ConnectRetryInterval = $retryInterval;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; database=$databaseName ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully on $number attempt.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect on $number attempt.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
TryToConnect( 10, 30, 'first');
|
||||
TryToConnect( 0, 30, 'second');
|
||||
TryToConnect( 256, 30, 'third');
|
||||
TryToConnect( 5, 70, 'fourth');
|
||||
TryToConnect( -1, 30, 'fifth');
|
||||
TryToConnect( 'thisisnotaninteger', 30, 'sixth');
|
||||
TryToConnect( 5, 3.14159, 'seventh');
|
||||
|
||||
$connectionInfo = "ConnectRetryCount;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; database=$databaseName ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully on eighth attempt.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect on eighth attempt.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$connectionInfo = "ConnectRetryInterval;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; database=$databaseName ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully on ninth attempt.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect on ninth attempt.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Connected successfully on first attempt.
|
||||
Connected successfully on second attempt.
|
||||
Could not connect on third attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
Could not connect on fourth attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
Could not connect on fifth attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
Could not connect on sixth attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
Could not connect on seventh attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
Could not connect on eighth attempt.
|
||||
SQLSTATE\[IMSSP\]: The DSN string ended unexpectedly.
|
||||
Could not connect on ninth attempt.
|
||||
--TEST--
|
||||
Test the connection resiliency keywords ConnectRetryCount and ConnectRetryInterval and their ranges of acceptable values
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "MsSetup.inc" );
|
||||
|
||||
function TryToConnect( $retryCount, $retryInterval, $number )
|
||||
{
|
||||
global $server, $databaseName, $uid, $pwd;
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = $retryCount; ConnectRetryInterval = $retryInterval;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; database=$databaseName ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully on $number attempt.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect on $number attempt.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
|
||||
TryToConnect( 10, 30, 'first');
|
||||
TryToConnect( 0, 30, 'second');
|
||||
TryToConnect( 256, 30, 'third');
|
||||
TryToConnect( 5, 70, 'fourth');
|
||||
TryToConnect( -1, 30, 'fifth');
|
||||
TryToConnect( 'thisisnotaninteger', 30, 'sixth');
|
||||
TryToConnect( 5, 3.14159, 'seventh');
|
||||
|
||||
$connectionInfo = "ConnectRetryCount;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; database=$databaseName ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully on eighth attempt.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect on eighth attempt.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
$connectionInfo = "ConnectRetryInterval;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; database=$databaseName ; $connectionInfo", $uid, $pwd );
|
||||
echo "Connected successfully on ninth attempt.\n";
|
||||
$conn = null;
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect on ninth attempt.\n";
|
||||
print_r( $e->getMessage() );
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Connected successfully on first attempt.
|
||||
Connected successfully on second attempt.
|
||||
Could not connect on third attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
Could not connect on fourth attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
Could not connect on fifth attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
Could not connect on sixth attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
Could not connect on seventh attempt.
|
||||
SQLSTATE\[08001\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
Could not connect on eighth attempt.
|
||||
SQLSTATE\[IMSSP\]: The DSN string ended unexpectedly.
|
||||
Could not connect on ninth attempt.
|
||||
SQLSTATE\[IMSSP\]: The DSN string ended unexpectedly.
|
|
@ -1,216 +1,217 @@
|
|||
--TEST--
|
||||
Test connection resiliency with a prepared statement and transaction.
|
||||
--DESCRIPTION--
|
||||
Prepare a statement, break the connection, and execute the statement. Then
|
||||
test transactions by breaking the connection before beginning a transaction
|
||||
and in the middle of the transaction. The latter case should fail.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break_pdo.php" );
|
||||
|
||||
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Statement expected to be executed because the connection is idle after
|
||||
// statement has been prepared
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$stmt1 = $conn->prepare( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt1 ) echo "Statement 1 prepared.\n";
|
||||
else echo "Error preparing statement 1.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Exception preparing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
if ( $stmt1->execute() ) echo "Statement 1 executed.\n";
|
||||
else echo "Statement 1 failed.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Exception executing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Transaction should be committed because connection is broken before
|
||||
// transaction begins
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
if ( $conn->beginTransaction() ) echo "Transaction begun.\n";
|
||||
else echo "Could not begin transaction.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "Exception: could not begin transaction.\n";
|
||||
}
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( 700, 'zyxwv' )";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->query( $tsql );
|
||||
|
||||
if ( $stmt2 )
|
||||
{
|
||||
if ( $conn->commit() )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $conn->rollBack() )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to trigger an error because connection is interrupted in the middle
|
||||
// of a transaction
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( $conn->beginTransaction() ) echo "Transaction begun.\n";
|
||||
else echo "Could not begin transaction.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "Exception: could not begin transaction.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( 700, 'zyxwv' )";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->query( $tsql );
|
||||
|
||||
if ( $stmt2 )
|
||||
{
|
||||
if ( $conn->commit() )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $conn->rollBack() )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
// This try catch block prevents an Uncaught PDOException error that occurs
|
||||
// when trying to free the connection.
|
||||
try
|
||||
{
|
||||
$conn = null;
|
||||
}
|
||||
catch ( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn_break = null;
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 prepared.
|
||||
Statement 1 executed.
|
||||
Transaction begun.
|
||||
Transaction was committed.
|
||||
Transaction begun.
|
||||
SQLSTATE\[08S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
SQLSTATE\[08S01\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
--TEST--
|
||||
Test connection resiliency with a prepared statement and transaction.
|
||||
--DESCRIPTION--
|
||||
Prepare a statement, break the connection, and execute the statement. Then
|
||||
test transactions by breaking the connection before beginning a transaction
|
||||
and in the middle of the transaction. The latter case should fail.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break_pdo.php" );
|
||||
|
||||
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Statement expected to be executed because the connection is idle after
|
||||
// statement has been prepared
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$stmt1 = $conn->prepare( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt1 ) echo "Statement 1 prepared.\n";
|
||||
else echo "Error preparing statement 1.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Exception preparing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
if ( $stmt1->execute() ) echo "Statement 1 executed.\n";
|
||||
else echo "Statement 1 failed.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Exception executing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Transaction should be committed because connection is broken before
|
||||
// transaction begins
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
if ( $conn->beginTransaction() ) echo "Transaction begun.\n";
|
||||
else echo "Could not begin transaction.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "Exception: could not begin transaction.\n";
|
||||
}
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( 700, 'zyxwv' )";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->query( $tsql );
|
||||
|
||||
if ( $stmt2 )
|
||||
{
|
||||
if ( $conn->commit() )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $conn->rollBack() )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to trigger an error because connection is interrupted in the middle
|
||||
// of a transaction
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( $conn->beginTransaction() ) echo "Transaction begun.\n";
|
||||
else echo "Could not begin transaction.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
echo "Exception: could not begin transaction.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( 700, 'zyxwv' )";
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->query( $tsql );
|
||||
|
||||
if ( $stmt2 )
|
||||
{
|
||||
if ( $conn->commit() )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $conn->rollBack() )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
// This try catch block prevents an Uncaught PDOException error that occurs
|
||||
// when trying to free the connection.
|
||||
try
|
||||
{
|
||||
$conn = null;
|
||||
}
|
||||
catch ( PDOException $e )
|
||||
{
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn_break = null;
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 prepared.
|
||||
Statement 1 executed.
|
||||
Transaction begun.
|
||||
Transaction was committed.
|
||||
Transaction begun.
|
||||
SQLSTATE\[08S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
SQLSTATE\[08S01\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
|
|
|
@ -1,87 +1,88 @@
|
|||
--TEST--
|
||||
Test connection resiliency timeouts
|
||||
--DESCRIPTION--
|
||||
1. Connect with ConnectRetryCount equal to 0.
|
||||
2. Reconnect with the default value of ConnectRetryCount(1).
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break_pdo.php" );
|
||||
|
||||
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to error out because ConnectRetryCount equals 0
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 0;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
$stmt1 = $conn->query( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt1 ) echo "Query successfully executed.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to succeed with a single reconnection attempt
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryInterval = 10;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->query( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt2 ) echo "Query successfully executed.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 2.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
$conn_break = null;
|
||||
|
||||
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Error executing statement 1.
|
||||
SQLSTATE\[08S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
Query successfully executed.
|
||||
--TEST--
|
||||
Test connection resiliency timeouts
|
||||
--DESCRIPTION--
|
||||
1. Connect with ConnectRetryCount equal to 0.
|
||||
2. Reconnect with the default value of ConnectRetryCount(1).
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break_pdo.php" );
|
||||
|
||||
$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to error out because ConnectRetryCount equals 0
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryCount = 0;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
$stmt1 = $conn->query( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt1 ) echo "Query successfully executed.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 1.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to succeed with a single reconnection attempt
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = "ConnectRetryInterval = 10;";
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd );
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
try
|
||||
{
|
||||
$stmt2 = $conn->query( "SELECT * FROM $tableName1" );
|
||||
if ( $stmt2 ) echo "Query successfully executed.\n";
|
||||
}
|
||||
catch( PDOException $e )
|
||||
{
|
||||
echo "Error executing statement 2.\n";
|
||||
print_r( $e->getMessage() );
|
||||
}
|
||||
|
||||
$conn = null;
|
||||
$conn_break = null;
|
||||
|
||||
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Error executing statement 1.
|
||||
SQLSTATE\[08S02\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
Query successfully executed.
|
||||
|
|
28
test/functional/pdo_sqlsrv/skipif_version_not_2k16.inc
Normal file
28
test/functional/pdo_sqlsrv/skipif_version_not_2k16.inc
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
if ( !( strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN' ) ) die( "Skip Test on windows only." );
|
||||
|
||||
if (!extension_loaded("pdo_sqlsrv")) {
|
||||
die("skip Extension not loaded");
|
||||
}
|
||||
|
||||
require_once( "MsSetup.inc" );
|
||||
|
||||
$conn = new PDO( "sqlsrv:server = $server ;", $uid, $pwd );
|
||||
if ($conn === false) {
|
||||
die( "skip Could not connect during SKIPIF." );
|
||||
}
|
||||
|
||||
// Get SQL Server Version
|
||||
$stmt = $conn->query( "SELECT @@VERSION" );
|
||||
if ($stmt) {
|
||||
$ver_string = $stmt->fetch(PDO::FETCH_NUM)[0];
|
||||
} else {
|
||||
die( "skip Could not fetch SQL Server version during SKIPIF.");
|
||||
}
|
||||
|
||||
$version = explode(' ', $ver_string);
|
||||
|
||||
if ($version[3] < '2016') {
|
||||
die("skip Wrong version of SQL Server, 2016 or later required");
|
||||
}
|
||||
?>
|
|
@ -1,262 +1,263 @@
|
|||
--TEST--
|
||||
Connection recovery test
|
||||
--DESCRIPTION--
|
||||
Connect and execute a command, kill the connection, execute another command.
|
||||
Then do it again without a buffered result set, by freeing the statement before
|
||||
killing the connection and then not freeing it. The latter case is the only one
|
||||
that should fail. Finally, execute two queries in two threads on a recovered
|
||||
non-MARS connection. This should fail too.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
// There is a lot of repeated code here that could be refactored with helper methods,
|
||||
// mostly for statement allocation. But that would affect scoping for the $stmt variables,
|
||||
// which could affect the results when attempting to reconnect. What happens to statements
|
||||
// when exiting the helper method? Do the associated cursors remain active? It is an
|
||||
// unnecessary complication, so I have left the code like this.
|
||||
|
||||
require_once( "break.php" );
|
||||
|
||||
$conn_break = sqlsrv_connect( $server, array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd) );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to successfully execute second query because buffered cursor for
|
||||
// first query means connection is idle when broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd, "ConnectionPooling"=>false,
|
||||
"ConnectRetryCount"=>10, "ConnectRetryInterval"=>10 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt1 = sqlsrv_query( $conn, "SELECT * FROM $tableName1", array(), array( "Scrollable"=>"buffered" ) );
|
||||
if( $stmt1 === false )
|
||||
{
|
||||
echo "Error in statement 1.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt1 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt2 = sqlsrv_query( $conn, "SELECT * FROM $tableName2", array(), array( "Scrollable"=>"buffered" ) );
|
||||
if( $stmt2 === false )
|
||||
{
|
||||
echo "Error in statement 2.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 2 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt2 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to successfully execute second query because first statement is
|
||||
// freed before breaking connection
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt3 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt3 === false )
|
||||
{
|
||||
echo "Error in statement 3.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 3 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt3 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt3 );
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt4 = sqlsrv_query( $conn, "SELECT * FROM $tableName2" );
|
||||
if( $stmt4 === false )
|
||||
{
|
||||
echo "Error in statement 4.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 4 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt4 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to fail executing second query because default cursor for first
|
||||
// query is still active when connection is broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt5 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt5 === false )
|
||||
{
|
||||
echo "Error in statement 5.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 5 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt5 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt6 = sqlsrv_query( $conn, "SELECT * FROM $tableName2" );
|
||||
if( $stmt6 === false )
|
||||
{
|
||||
echo "Error in statement 6.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 6 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt6 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 4
|
||||
// Expected to trigger an error because there are two active statements with
|
||||
// pending results and MARS is off
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ConnectRetryCount"=>10, "ConnectRetryInterval"=>10, "MultipleActiveResultSets"=>false );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt7 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt7 === false )
|
||||
{
|
||||
echo "Error in statement 7.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 7 successful.\n";
|
||||
}
|
||||
|
||||
$stmt8 = sqlsrv_query( $conn, "SELECT * FROM $tableName2" );
|
||||
if( $stmt8 === false )
|
||||
{
|
||||
echo "Error in statement 8.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 8 successful.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
sqlsrv_close( $conn_break );
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 successful.
|
||||
16 rows in result set.
|
||||
Statement 2 successful.
|
||||
9 rows in result set.
|
||||
Statement 3 successful.
|
||||
rows in result set.
|
||||
Statement 4 successful.
|
||||
rows in result set.
|
||||
Statement 5 successful.
|
||||
rows in result set.
|
||||
Error in statement 6.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\)
|
||||
|
||||
\)
|
||||
Statement 7 successful.
|
||||
Error in statement 8.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -44
|
||||
\[code\] => -44
|
||||
\[2\] => The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option.
|
||||
\[message\] => The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option.
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => HY000
|
||||
\[SQLSTATE\] => HY000
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Connection is busy with results for another command
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Connection is busy with results for another command
|
||||
\)
|
||||
|
||||
\)
|
||||
--TEST--
|
||||
Connection recovery test
|
||||
--DESCRIPTION--
|
||||
Connect and execute a command, kill the connection, execute another command.
|
||||
Then do it again without a buffered result set, by freeing the statement before
|
||||
killing the connection and then not freeing it. The latter case is the only one
|
||||
that should fail. Finally, execute two queries in two threads on a recovered
|
||||
non-MARS connection. This should fail too.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
// There is a lot of repeated code here that could be refactored with helper methods,
|
||||
// mostly for statement allocation. But that would affect scoping for the $stmt variables,
|
||||
// which could affect the results when attempting to reconnect. What happens to statements
|
||||
// when exiting the helper method? Do the associated cursors remain active? It is an
|
||||
// unnecessary complication, so I have left the code like this.
|
||||
|
||||
require_once( "break.php" );
|
||||
|
||||
$conn_break = sqlsrv_connect( $server, array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd) );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to successfully execute second query because buffered cursor for
|
||||
// first query means connection is idle when broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd, "ConnectionPooling"=>false,
|
||||
"ConnectRetryCount"=>10, "ConnectRetryInterval"=>10 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt1 = sqlsrv_query( $conn, "SELECT * FROM $tableName1", array(), array( "Scrollable"=>"buffered" ) );
|
||||
if( $stmt1 === false )
|
||||
{
|
||||
echo "Error in statement 1.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt1 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt2 = sqlsrv_query( $conn, "SELECT * FROM $tableName2", array(), array( "Scrollable"=>"buffered" ) );
|
||||
if( $stmt2 === false )
|
||||
{
|
||||
echo "Error in statement 2.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 2 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt2 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to successfully execute second query because first statement is
|
||||
// freed before breaking connection
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt3 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt3 === false )
|
||||
{
|
||||
echo "Error in statement 3.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 3 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt3 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt3 );
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt4 = sqlsrv_query( $conn, "SELECT * FROM $tableName2" );
|
||||
if( $stmt4 === false )
|
||||
{
|
||||
echo "Error in statement 4.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 4 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt4 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to fail executing second query because default cursor for first
|
||||
// query is still active when connection is broken
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt5 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt5 === false )
|
||||
{
|
||||
echo "Error in statement 5.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 5 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt5 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt6 = sqlsrv_query( $conn, "SELECT * FROM $tableName2" );
|
||||
if( $stmt6 === false )
|
||||
{
|
||||
echo "Error in statement 6.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 6 successful.\n";
|
||||
$rowcount = sqlsrv_num_rows( $stmt6 );
|
||||
echo $rowcount." rows in result set.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 4
|
||||
// Expected to trigger an error because there are two active statements with
|
||||
// pending results and MARS is off
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ConnectRetryCount"=>10, "ConnectRetryInterval"=>10, "MultipleActiveResultSets"=>false );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt7 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt7 === false )
|
||||
{
|
||||
echo "Error in statement 7.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 7 successful.\n";
|
||||
}
|
||||
|
||||
$stmt8 = sqlsrv_query( $conn, "SELECT * FROM $tableName2" );
|
||||
if( $stmt8 === false )
|
||||
{
|
||||
echo "Error in statement 8.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 8 successful.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
sqlsrv_close( $conn_break );
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 successful.
|
||||
16 rows in result set.
|
||||
Statement 2 successful.
|
||||
9 rows in result set.
|
||||
Statement 3 successful.
|
||||
rows in result set.
|
||||
Statement 4 successful.
|
||||
rows in result set.
|
||||
Statement 5 successful.
|
||||
rows in result set.
|
||||
Error in statement 6.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\)
|
||||
|
||||
\)
|
||||
Statement 7 successful.
|
||||
Error in statement 8.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -44
|
||||
\[code\] => -44
|
||||
\[2\] => The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option.
|
||||
\[message\] => The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option.
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => HY000
|
||||
\[SQLSTATE\] => HY000
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Connection is busy with results for another command
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Connection is busy with results for another command
|
||||
\)
|
||||
|
||||
\)
|
||||
|
|
|
@ -1,166 +1,167 @@
|
|||
--TEST--
|
||||
Test the connection resiliency keywords
|
||||
--DESCRIPTION--
|
||||
Test the connection resiliency keywords ConnectRetryCount and ConnectRetryInterval and their ranges of acceptable values
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "MsSetup.inc" );
|
||||
|
||||
function TryToConnect( $server, $userName, $userPassword, $retryCount, $retryInterval, $number )
|
||||
{
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword,
|
||||
"ConnectRetryCount"=>$retryCount, "ConnectRetryInterval"=>$retryInterval );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect on $number attempt.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully on $number attempt.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
}
|
||||
|
||||
TryToConnect( $server, $userName, $userPassword, 10, 30, 'first');
|
||||
TryToConnect( $server, $userName, $userPassword, 0, 30, 'second');
|
||||
TryToConnect( $server, $userName, $userPassword, 256, 30, 'third');
|
||||
TryToConnect( $server, $userName, $userPassword, 5, 70, 'fourth');
|
||||
TryToConnect( $server, $userName, $userPassword, -1, 30, 'fifth');
|
||||
TryToConnect( $server, $userName, $userPassword, 'thisisnotaninteger', 30, 'sixth');
|
||||
TryToConnect( $server, $userName, $userPassword, 5, 3.14159, 'seventh');
|
||||
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword, "ConnectRetryCount" );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect on eighth attempt.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully on eighth attempt.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword, "ConnectRetryInterval" );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect on ninth attempt.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully on ninth attempt.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Connected successfully on first attempt.
|
||||
Connected successfully on second attempt.
|
||||
Could not connect on third attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08001
|
||||
\[SQLSTATE\] => 08001
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on fourth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08001
|
||||
\[SQLSTATE\] => 08001
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on fifth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08001
|
||||
\[SQLSTATE\] => 08001
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on sixth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -33
|
||||
\[code\] => -33
|
||||
\[2\] => Invalid value type for option ConnectRetryCount was specified. Integer type was expected.
|
||||
\[message\] => Invalid value type for option ConnectRetryCount was specified. Integer type was expected.
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on seventh attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -33
|
||||
\[code\] => -33
|
||||
\[2\] => Invalid value type for option ConnectRetryInterval was specified. Integer type was expected.
|
||||
\[message\] => Invalid value type for option ConnectRetryInterval was specified. Integer type was expected.
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on eighth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -8
|
||||
\[code\] => -8
|
||||
\[2\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\[message\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on ninth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -8
|
||||
\[code\] => -8
|
||||
\[2\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\[message\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\)
|
||||
|
||||
--TEST--
|
||||
Test the connection resiliency keywords
|
||||
--DESCRIPTION--
|
||||
Test the connection resiliency keywords ConnectRetryCount and ConnectRetryInterval and their ranges of acceptable values
|
||||
--SKIPIF--
|
||||
<?php require('skipif_unix.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "MsSetup.inc" );
|
||||
|
||||
function TryToConnect( $server, $userName, $userPassword, $retryCount, $retryInterval, $number )
|
||||
{
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword,
|
||||
"ConnectRetryCount"=>$retryCount, "ConnectRetryInterval"=>$retryInterval );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect on $number attempt.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully on $number attempt.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
}
|
||||
|
||||
TryToConnect( $server, $userName, $userPassword, 10, 30, 'first');
|
||||
TryToConnect( $server, $userName, $userPassword, 0, 30, 'second');
|
||||
TryToConnect( $server, $userName, $userPassword, 256, 30, 'third');
|
||||
TryToConnect( $server, $userName, $userPassword, 5, 70, 'fourth');
|
||||
TryToConnect( $server, $userName, $userPassword, -1, 30, 'fifth');
|
||||
TryToConnect( $server, $userName, $userPassword, 'thisisnotaninteger', 30, 'sixth');
|
||||
TryToConnect( $server, $userName, $userPassword, 5, 3.14159, 'seventh');
|
||||
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword, "ConnectRetryCount" );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect on eighth attempt.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully on eighth attempt.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword, "ConnectRetryInterval" );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect on ninth attempt.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully on ninth attempt.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Connected successfully on first attempt.
|
||||
Connected successfully on second attempt.
|
||||
Could not connect on third attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08001
|
||||
\[SQLSTATE\] => 08001
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on fourth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08001
|
||||
\[SQLSTATE\] => 08001
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryInterval'
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on fifth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08001
|
||||
\[SQLSTATE\] => 08001
|
||||
\[1\] => 0
|
||||
\[code\] => 0
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Invalid value specified for connection string attribute 'ConnectRetryCount'
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on sixth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -33
|
||||
\[code\] => -33
|
||||
\[2\] => Invalid value type for option ConnectRetryCount was specified. Integer type was expected.
|
||||
\[message\] => Invalid value type for option ConnectRetryCount was specified. Integer type was expected.
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on seventh attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -33
|
||||
\[code\] => -33
|
||||
\[2\] => Invalid value type for option ConnectRetryInterval was specified. Integer type was expected.
|
||||
\[message\] => Invalid value type for option ConnectRetryInterval was specified. Integer type was expected.
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on eighth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -8
|
||||
\[code\] => -8
|
||||
\[2\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\[message\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\)
|
||||
|
||||
\)
|
||||
Could not connect on ninth attempt.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => IMSSP
|
||||
\[SQLSTATE\] => IMSSP
|
||||
\[1\] => -8
|
||||
\[code\] => -8
|
||||
\[2\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\[message\] => An invalid connection option key type was received. Option key types must be strings.
|
||||
\)
|
||||
|
||||
\)
|
|
@ -1,207 +1,208 @@
|
|||
--TEST--
|
||||
Test connection resiliency with a prepared statement and transaction.
|
||||
--DESCRIPTION--
|
||||
Prepare a statement, break the connection, and execute the statement. Then
|
||||
test transactions by breaking the connection before beginning a transaction
|
||||
and in the middle of the transaction. The latter case should fail (i.e., the
|
||||
transaction should be rolled back).
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break.php" );
|
||||
|
||||
$conn_break = sqlsrv_connect( $server, array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd) );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Statement expected to be executed because the connection is idle after
|
||||
// statement has been prepared
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd, "ConnectionPooling"=>false,
|
||||
"ConnectRetryCount"=>10, "ConnectRetryInterval"=>10 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt1 = sqlsrv_prepare( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt1 === false )
|
||||
{
|
||||
echo "Error in statement preparation.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 prepared.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
if( sqlsrv_execute( $stmt1 ) )
|
||||
{
|
||||
echo "Statement 1 executed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 could not be executed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Transaction should be committed because connection is broken before
|
||||
// transaction begins
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
if ( sqlsrv_begin_transaction( $conn ) === false )
|
||||
{
|
||||
echo "Could not begin transaction.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Transaction begun.\n";
|
||||
}
|
||||
|
||||
$number = 700;
|
||||
$string = 'zxywv';
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
|
||||
$params = array( $number, $string );
|
||||
$stmt2 = sqlsrv_query( $conn, $tsql, $params );
|
||||
|
||||
if( $stmt2 )
|
||||
{
|
||||
if ( sqlsrv_commit( $conn ) )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( sqlsrv_rollback( $conn ) )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to trigger an error because connection is interrupted in the middle
|
||||
// of a transaction
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
if ( sqlsrv_begin_transaction( $conn ) === false )
|
||||
{
|
||||
echo "Could not begin transaction.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Transaction begun.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$number = 700;
|
||||
$string = 'zxywv';
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
|
||||
$params = array( $number, $string );
|
||||
$stmt2 = sqlsrv_query( $conn, $tsql, $params );
|
||||
|
||||
if( $stmt2 )
|
||||
{
|
||||
if ( sqlsrv_commit( $conn ) )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( sqlsrv_rollback( $conn ) )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
sqlsrv_close( $conn_break );
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 prepared.
|
||||
Statement 1 executed.
|
||||
Transaction begun.
|
||||
Transaction was committed.
|
||||
Transaction begun.
|
||||
Statement not valid and rollback failed.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08S02
|
||||
\[SQLSTATE\] => 08S02
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 08S02
|
||||
\[SQLSTATE\] => 08S02
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Unable to open a logical session
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Unable to open a logical session
|
||||
\)
|
||||
|
||||
\)
|
||||
--TEST--
|
||||
Test connection resiliency with a prepared statement and transaction.
|
||||
--DESCRIPTION--
|
||||
Prepare a statement, break the connection, and execute the statement. Then
|
||||
test transactions by breaking the connection before beginning a transaction
|
||||
and in the middle of the transaction. The latter case should fail (i.e., the
|
||||
transaction should be rolled back).
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break.php" );
|
||||
|
||||
$conn_break = sqlsrv_connect( $server, array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd) );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Statement expected to be executed because the connection is idle after
|
||||
// statement has been prepared
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd, "ConnectionPooling"=>false,
|
||||
"ConnectRetryCount"=>10, "ConnectRetryInterval"=>10 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
$stmt1 = sqlsrv_prepare( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt1 === false )
|
||||
{
|
||||
echo "Error in statement preparation.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 prepared.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
if( sqlsrv_execute( $stmt1 ) )
|
||||
{
|
||||
echo "Statement 1 executed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 could not be executed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Transaction should be committed because connection is broken before
|
||||
// transaction begins
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
if ( sqlsrv_begin_transaction( $conn ) === false )
|
||||
{
|
||||
echo "Could not begin transaction.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Transaction begun.\n";
|
||||
}
|
||||
|
||||
$number = 700;
|
||||
$string = 'zxywv';
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
|
||||
$params = array( $number, $string );
|
||||
$stmt2 = sqlsrv_query( $conn, $tsql, $params );
|
||||
|
||||
if( $stmt2 )
|
||||
{
|
||||
if ( sqlsrv_commit( $conn ) )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( sqlsrv_rollback( $conn ) )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 3
|
||||
// Expected to trigger an error because connection is interrupted in the middle
|
||||
// of a transaction
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
if ( sqlsrv_begin_transaction( $conn ) === false )
|
||||
{
|
||||
echo "Could not begin transaction.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Transaction begun.\n";
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$number = 700;
|
||||
$string = 'zxywv';
|
||||
|
||||
$tsql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
|
||||
$params = array( $number, $string );
|
||||
$stmt2 = sqlsrv_query( $conn, $tsql, $params );
|
||||
|
||||
if( $stmt2 )
|
||||
{
|
||||
if ( sqlsrv_commit( $conn ) )
|
||||
{
|
||||
echo "Transaction was committed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement valid but commit failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( sqlsrv_rollback( $conn ) )
|
||||
{
|
||||
echo "Transaction was rolled back.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement not valid and rollback failed.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
sqlsrv_close( $conn_break );
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Statement 1 prepared.
|
||||
Statement 1 executed.
|
||||
Transaction begun.
|
||||
Transaction was committed.
|
||||
Transaction begun.
|
||||
Statement not valid and rollback failed.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08S02
|
||||
\[SQLSTATE\] => 08S02
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 08S02
|
||||
\[SQLSTATE\] => 08S02
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Unable to open a logical session
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Unable to open a logical session
|
||||
\)
|
||||
|
||||
\)
|
||||
|
|
|
@ -1,105 +1,106 @@
|
|||
--TEST--
|
||||
Test connection resiliency timeouts
|
||||
--DESCRIPTION--
|
||||
1. Connect with ConnectRetryCount equal to 0.
|
||||
2. Reconnect with the default value of ConnectRetryCount (the default is 1).
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break.php" );
|
||||
|
||||
$conn_break = sqlsrv_connect( $server, array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd) );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to error out because ConnectRetryCount equals 0
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ConnectRetryCount"=>0 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt1 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt1 === false )
|
||||
{
|
||||
echo "Error in statement 1.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 successful.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to succeed with a single reconnection attempt
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ConnectRetryInterval"=>10 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt2 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt2 === false )
|
||||
{
|
||||
echo "Error in statement 2.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 2 successful.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
sqlsrv_close( $conn_break );
|
||||
|
||||
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Error in statement 1.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\)
|
||||
|
||||
\)
|
||||
Statement 2 successful.
|
||||
--TEST--
|
||||
Test connection resiliency timeouts
|
||||
--DESCRIPTION--
|
||||
1. Connect with ConnectRetryCount equal to 0.
|
||||
2. Reconnect with the default value of ConnectRetryCount (the default is 1).
|
||||
--SKIPIF--
|
||||
<?php require('skipif_protocol_not_tcp.inc');
|
||||
require('skipif_version_not_2k14.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once( "break.php" );
|
||||
|
||||
$conn_break = sqlsrv_connect( $server, array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd) );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 1
|
||||
// Expected to error out because ConnectRetryCount equals 0
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ConnectRetryCount"=>0 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt1 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt1 === false )
|
||||
{
|
||||
echo "Error in statement 1.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 1 successful.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Part 2
|
||||
// Expected to succeed with a single reconnection attempt
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"ConnectRetryInterval"=>10 );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
BreakConnection( $conn, $conn_break );
|
||||
|
||||
$stmt2 = sqlsrv_query( $conn, "SELECT * FROM $tableName1" );
|
||||
if( $stmt2 === false )
|
||||
{
|
||||
echo "Error in statement 2.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Statement 2 successful.\n";
|
||||
}
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
sqlsrv_close( $conn_break );
|
||||
|
||||
DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Error in statement 1.
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]TCP Provider: An existing connection was forcibly closed by the remote host.
|
||||
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 08S01
|
||||
\[SQLSTATE\] => 08S01
|
||||
\[1\] => 10054
|
||||
\[code\] => 10054
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Communication link failure
|
||||
\)
|
||||
|
||||
\)
|
||||
Statement 2 successful.
|
||||
|
|
30
test/functional/sqlsrv/skipif_version_not_2k16.inc
Normal file
30
test/functional/sqlsrv/skipif_version_not_2k16.inc
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
if ( !( strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN' ) ) die( "Skip Test on windows only." );
|
||||
|
||||
if (!extension_loaded("sqlsrv")) {
|
||||
die("skip Extension not loaded");
|
||||
}
|
||||
|
||||
require_once( "MsSetup.inc" );
|
||||
|
||||
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if ($conn === false) {
|
||||
die( "skip Could not connect during SKIPIF." );
|
||||
}
|
||||
|
||||
// Get SQL Server version
|
||||
$stmt = sqlsrv_query( $conn, "SELECT @@VERSION" );
|
||||
if (sqlsrv_fetch($stmt)) {
|
||||
$ver_string = sqlsrv_get_field( $stmt, 0 );
|
||||
} else {
|
||||
die("skip Could not fetch SQL Server version.");
|
||||
}
|
||||
|
||||
$version = explode(' ', $ver_string);
|
||||
|
||||
if ($version[3] < '2016') {
|
||||
die("skip Wrong version of SQL Server, 2016 or later required");
|
||||
}
|
||||
?>
|
|
@ -1,109 +1,110 @@
|
|||
--TEST--
|
||||
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsSetup.inc");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with Authentication=SqlPassword.
|
||||
//
|
||||
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"Authentication"=>'SqlPassword', "TrustServerCertificate"=>true);
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect with Authentication=SqlPassword.\n";
|
||||
var_dump( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully with Authentication=SqlPassword.\n";
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "SELECT count(*) FROM cd_info" );
|
||||
if ( $stmt === false )
|
||||
{
|
||||
echo "Query failed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = sqlsrv_fetch_array( $stmt );
|
||||
var_dump( $result );
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with integrated authentication. This should fail because
|
||||
// we don't support it.
|
||||
//
|
||||
$connectionInfo = array( "Authentication"=>"ActiveDirectoryIntegrated", "TrustServerCertificate"=>true );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
$errors = sqlsrv_errors();
|
||||
print_r($errors[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
|
||||
// your credentials to test, or this part is skipped.
|
||||
//
|
||||
$azureServer = $adServer;
|
||||
$azureDatabase = $adDatabase;
|
||||
$azureUsername = $adUser;
|
||||
$azurePassword = $adPassword;
|
||||
|
||||
if ($azureServer != 'TARGET_AD_SERVER')
|
||||
{
|
||||
$connectionInfo = array( "UID"=>$azureUsername, "PWD"=>$azurePassword,
|
||||
"Authentication"=>'ActiveDirectoryPassword', "TrustServerCertificate"=>true );
|
||||
|
||||
$conn = sqlsrv_connect( $azureServer, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect with ActiveDirectoryPassword.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Connected successfully with Authentication=SqlPassword.
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(7)
|
||||
[""]=>
|
||||
int(7)
|
||||
}
|
||||
Could not connect with Authentication=ActiveDirectoryIntegrated.
|
||||
Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -62
|
||||
[code] => -62
|
||||
[2] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
|
||||
[message] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
|
||||
)
|
||||
%s with Authentication=ActiveDirectoryPassword.
|
||||
--TEST--
|
||||
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc');
|
||||
require('skipif_version_not_2k16.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsSetup.inc");
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with Authentication=SqlPassword.
|
||||
//
|
||||
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||
"Authentication"=>'SqlPassword', "TrustServerCertificate"=>true);
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect with Authentication=SqlPassword.\n";
|
||||
var_dump( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully with Authentication=SqlPassword.\n";
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "SELECT count(*) FROM cd_info" );
|
||||
if ( $stmt === false )
|
||||
{
|
||||
echo "Query failed.\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = sqlsrv_fetch_array( $stmt );
|
||||
var_dump( $result );
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD with integrated authentication. This should fail because
|
||||
// we don't support it.
|
||||
//
|
||||
$connectionInfo = array( "Authentication"=>"ActiveDirectoryIntegrated", "TrustServerCertificate"=>true );
|
||||
|
||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
$errors = sqlsrv_errors();
|
||||
print_r($errors[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryIntegrated.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
|
||||
// your credentials to test, or this part is skipped.
|
||||
//
|
||||
$azureServer = $adServer;
|
||||
$azureDatabase = $adDatabase;
|
||||
$azureUsername = $adUser;
|
||||
$azurePassword = $adPassword;
|
||||
|
||||
if ($azureServer != 'TARGET_AD_SERVER')
|
||||
{
|
||||
$connectionInfo = array( "UID"=>$azureUsername, "PWD"=>$azurePassword,
|
||||
"Authentication"=>'ActiveDirectoryPassword', "TrustServerCertificate"=>true );
|
||||
|
||||
$conn = sqlsrv_connect( $azureServer, $connectionInfo );
|
||||
if( $conn === false )
|
||||
{
|
||||
echo "Could not connect with ActiveDirectoryPassword.\n";
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
|
||||
sqlsrv_close( $conn );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Connected successfully with Authentication=SqlPassword.
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(7)
|
||||
[""]=>
|
||||
int(7)
|
||||
}
|
||||
Could not connect with Authentication=ActiveDirectoryIntegrated.
|
||||
Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -62
|
||||
[code] => -62
|
||||
[2] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
|
||||
[message] => Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.
|
||||
)
|
||||
%s with Authentication=ActiveDirectoryPassword.
|
||||
|
|
Loading…
Reference in a new issue