Connecting through PHP to an SQL Server, using the Windows account

Viewed 17733

I am trying to connect using PHP to an SQL Server on another machine. I have found two ways of doing this. Either with odbc_connect or sqlsrvr connect.

    $connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$serverName;Database=$db;", 'user', 'pass');

or

  $conn = sqlsrv_connect($serverName, array('UID' => '', 'PWD' => ''));

The connection works if I try to connect to an SQL account. Unfortunately I cannot manage to connect using the Windows Authentication.

So far I have tried the following : used a working pass, added Trusted_Connection=yes; or Integrated Security=SSPI; . I have also tried combining this with fastcgi.impersonate = 1 or 0.

When I use directly my user and pass I get a login denied error and when I try the windows authentication with sspi I receive the following error:Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

I've googled the problem a lot but I could not find a solution. Some people however were talking about php not using the Network Service account and that that might be the problem.

Does anyone know how I could fix this or maybe give me a lead?

Thank you in advance.

6 Answers
  1. Open the IIS Console
  2. Go to your site
  3. Open "Authentication" settings Right-click on "Anonymous Authentication" and click on "Edit" By last select the option: Application pool identity (radio button) and press the "OK" button to apply the changes.
  4. Go to "Application Pools" and get the application pool name.
  5. Open SSMS (SQL management studio), enter the relevant database and choose "Security".
  6. Add a new user, fill only the name and save. The name of the user should be: IIS APPPOOL\{YOUR_APP_POOL_NAME}

Good luck!

Related