2017-09-30 07:11:45 +03:00
|
|
|
--TEST--
|
|
|
|
Test the Authentication keyword and three options: SqlPassword, ActiveDirectoryIntegrated, and ActiveDirectoryPassword.
|
|
|
|
--SKIPIF--
|
|
|
|
<?php require('skipif.inc');
|
2017-10-05 23:24:46 +03:00
|
|
|
require('skipif_version_less_than_2k16.inc'); ?>
|
2017-09-30 07:11:45 +03:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
require_once("MsSetup.inc");
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Test Azure AD with Authentication=SqlPassword.
|
|
|
|
//
|
|
|
|
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
|
|
|
"Authentication"=>'SqlPassword', "TrustServerCertificate"=>true);
|
|
|
|
|
2019-01-08 02:36:59 +03:00
|
|
|
$conn = sqlsrv_connect($server, $connectionInfo);
|
2017-09-30 07:11:45 +03:00
|
|
|
|
2019-01-08 02:36:59 +03:00
|
|
|
if ($conn === false) {
|
2017-09-30 07:11:45 +03:00
|
|
|
echo "Could not connect with Authentication=SqlPassword.\n";
|
2019-01-08 02:36:59 +03:00
|
|
|
var_dump(sqlsrv_errors());
|
|
|
|
} else {
|
2017-09-30 07:11:45 +03:00
|
|
|
echo "Connected successfully with Authentication=SqlPassword.\n";
|
|
|
|
}
|
|
|
|
|
2019-01-08 02:36:59 +03:00
|
|
|
// For details, https://docs.microsoft.com/sql/t-sql/functions/serverproperty-transact-sql
|
|
|
|
$stmt = sqlsrv_query($conn, "SELECT SERVERPROPERTY('EngineEdition')");
|
|
|
|
if (sqlsrv_fetch($stmt)) {
|
|
|
|
$edition = sqlsrv_get_field($stmt, 0);
|
|
|
|
var_dump($edition);
|
|
|
|
} else {
|
2017-09-30 07:11:45 +03:00
|
|
|
echo "Query failed.\n";
|
|
|
|
}
|
|
|
|
|
2019-01-08 02:36:59 +03:00
|
|
|
sqlsrv_free_stmt($stmt);
|
|
|
|
sqlsrv_close($conn);
|
2017-09-30 07:11:45 +03:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Test Azure AD on an Azure database instance. Replace $azureServer, etc with
|
|
|
|
// your credentials to test, or this part is skipped.
|
|
|
|
//
|
2019-04-15 22:22:26 +03:00
|
|
|
function connectAzureDB($showException)
|
|
|
|
{
|
|
|
|
global $adServer, $adUser, $adPassword, $maxAttempts;
|
|
|
|
|
|
|
|
$connectionInfo = array("UID"=>$adUser,
|
|
|
|
"PWD"=>$adPassword,
|
|
|
|
"Authentication"=>'ActiveDirectoryPassword',
|
|
|
|
"TrustServerCertificate"=>false );
|
|
|
|
|
|
|
|
$conn = false;
|
|
|
|
$conn = sqlsrv_connect($adServer, $connectionInfo);
|
2019-01-08 02:36:59 +03:00
|
|
|
if ($conn === false) {
|
2019-04-15 22:22:26 +03:00
|
|
|
if ($showException) {
|
|
|
|
echo "Could not connect with ActiveDirectoryPassword after $maxAttempts retries.\n";
|
|
|
|
print_r(sqlsrv_errors());
|
|
|
|
}
|
2019-01-08 02:36:59 +03:00
|
|
|
} else {
|
2017-09-30 07:11:45 +03:00
|
|
|
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
|
2019-01-08 02:36:59 +03:00
|
|
|
sqlsrv_close($conn);
|
2017-09-30 07:11:45 +03:00
|
|
|
}
|
2019-04-15 22:22:26 +03:00
|
|
|
|
|
|
|
return $conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
$azureServer = $adServer;
|
|
|
|
$maxAttempts = 3;
|
|
|
|
|
|
|
|
if ($azureServer != 'TARGET_AD_SERVER') {
|
|
|
|
$conn = false;
|
|
|
|
$numAttempts = 0;
|
|
|
|
do {
|
|
|
|
$conn = connectAzureDB($numAttempts == ($maxAttempts - 1));
|
|
|
|
if ($conn === false) {
|
|
|
|
$numAttempts++;
|
|
|
|
sleep(10);
|
|
|
|
}
|
|
|
|
} while ($conn === false && $numAttempts < $maxAttempts);
|
|
|
|
|
2019-01-08 02:36:59 +03:00
|
|
|
} else {
|
2017-09-30 07:11:45 +03:00
|
|
|
echo "Not testing with Authentication=ActiveDirectoryPassword.\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECTF--
|
|
|
|
Connected successfully with Authentication=SqlPassword.
|
2019-01-08 02:36:59 +03:00
|
|
|
string(1) "%d"
|
2017-09-30 07:11:45 +03:00
|
|
|
%s with Authentication=ActiveDirectoryPassword.
|