6

Can I connect to SQL Server 2008 using PDO and integrated security using the mssql driver? Currently doing something like this to connect normally:

$db = new PDO("mssql:host=host;dbname=db", "user", "pass"); 

This works fine using SQL Server authentication, but it is a pain having to create SQL server logins for loads of databases, so it would be nice to use integrated security if possible. I am running PHP as CLI on Windows.

j0k
  • 22,600
  • 28
  • 79
  • 90
Tom Haigh
  • 57,217
  • 21
  • 114
  • 142

1 Answers1

9

This site helped: SQL Server Driver for PHP: Understanding Windows Authentication

The gist of it that fixed my issue was:

  • Enable Windows Authentication
  • Disable Anonymous Authentication
  • remove the username and password from the PDO connection
$conn = new PDO( "sqlsrv:server=$serverName ; Database=$dbName" );

My testing was with the newest driver released June 2010 (SQL Server Driver for PHP 2.0 CTP2).

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Curtis
  • 401
  • 4
  • 16