My environment:
– Windows Server 2008 R2.
– Apache Webserver.
– PHP 5.4.7
I’ve just downloaded and installed Microsoft Drivers 3.0 for PHP for SQL Server.
I’ve included “php_pdo_sqlsrv_54_ts.dll” into php.
Microsoft has included a helpful chm file with the drivers (SQLSRV_Help.chm).
In this help file there is a PDO example using windows authentication:
/* Connect using Windows Authentication. */
try {
$conn = new PDO("sqlsrv:server=$serverName ; Database=AdventureWorks", "", "");
$conn->setAttribute( PDO::ATTR ERRMOE, PDO::ERRMODE EXCEPTION );
}
But I have to connect to our MS SQL Server 2008 R2 using SQL Server Authentication!
What is the difference is between connecting to SQL Server
- using PDO and Windows Authentication
- using PDO and SQL Server Authentication
Is it just the connect string? Do I have to write:
$conn = new PDO("sqlsrv:server=$serverName; Database=AdventureWorks; UID=sa; PWD=abc");
or do I have to write:
$conn = new PDO("sqlsrv:server=$serverName; Database=AdventureWorks; User Id=sa; password=abc");
Thanks in advance
Update:
I found a resoure:
There are optional second and third parameter in the constructor which specify the username and password as described here:
This implies that you can connect to SQL Server using PDO + SQL authentication like this:
The connection options section also mentions that you cannot use
UIDandPWDparameters in connection strings when using PDO_SQLSRV.