Windows – sqlsrv_connect: use Windows authentication

authenticationPHPwindows

I have a PHP server running under IIS on serverIIS1, and a MS SQL database on serverDB4. I created some PHP code that runs on the serverIIS1 server:

$serverName = "serverDB4\serverDB4";
$connectionInfo = array( "Database"=>"DATABASE_NAME", "UID"=>"DOMAIN.ORG\\databaseadm", "PWD"=>"passwordishere");

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

I verified all this info is correct (the login is a Windows account with proper access, so it's via Windows authentication), but I'm getting this error:

Login failed for user 'DOMAIN.ORG\databaseadm'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'DOMAIN.ORG\databaseadm'. )

Why is the login failing? I know the info is right, as I can connect manually remotely via SQL Server Management Studio with those details.

Is it because I'm using Windows authentication? If that does not allow plaintext auth, how can I sqlsrv_connect with a Windows password?

Best Answer

As stated in the documentation you do not pass the UID and PWD to utilize Windows Authentication. You can see an example here.

From remarks within documentation link:

If values for the UID and PWD keys are not specified in the optional $connectionInfo parameter, the connection will be attempted using Windows Authentication. For more information about connecting to the server, see How to: Connect Using Windows Authentication and How to: Connect Using SQL Server Authentication.