Im trying to connect to AzureDB from PHP via Microsoft Entra Auth as described below,using sqlsrv driver:
https://learn.microsoft.com/en-us/sql/connect/php/azure-active-directory?view=sql-server-ver15#example—connect-using-azure-ad-access-token
Used script:
<?php
$azureAdServer = 'xxx.crm4.dynamics.com,5558';
$accToken = 'xxx>';
$azureAdDatabase = 'xxx';
// Using an access token to connect: do not use UID or PWD connection options
// Assume $accToken is the valid byte string extracted from an OAuth JSON response
$connectionInfo = array("Database"=>$azureAdDatabase,"AccessToken"=>$accToken);
$conn = sqlsrv_connect($azureAdServer, $connectionInfo);
if ($conn === false) {
echo "Could not connect with Azure AD Access Token.n";
die( print_r( sqlsrv_errors(), true));
} else {
echo "Connected successfully with Azure AD Access Token.n";
sqlsrv_close($conn);
}
?>
always get:
Could not connect with Azure AD Access Token
I can confirm that credentials are correct, connection via c# works, see below:
Image of C# code which works
Do you have any clue if that script working? I’ve spent a couple of hours with this connection and don´t have any other idea. AI fails too.
Thank you in advance for any help.
Michal
opentux is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.