PHP + MSSQL + Windows Server

This post assumes that you are running an up to date Windows Server 2003, Windows Server 2008, or Windows Server 2008 r2 operating system and a configured MSSQL Server.

As of PHP 5.3, the MS SQL database extension is no longer supplied with PHP on Windows. The alternative solution is now provided by Microsoft.

First, download and install Microsoft's solution, which can be found here:

At the time of writing this, the latest version is 3.0. After you have downloaded the drivers, run the file and extract the contents into a folder on the desktop as this version contains extensions for both PHP 5.3 and 5.4. Files in the format *_53*.dll and *_54*.dll are for PHP 5.3 and 5.4, respectively.

I have PHP 5.3 installed on Windows Server 2008 in the C:\Program Files (x86)\PHP directory. Therefore, the I need to edit the C:\Program Files (x86)\PHP\php.ini file by adding the following lines:


extension=php_pdo_sqlsrv_53_ts.dll ; This requires that php_pdo.dll be available as a compiled in module or as a loadable extension.

You can test to see if the drivers loaded by either restarted the web server or by running php on the command line. I prefer to do the latter of the methods because if there is something wrong such as a missing DLL, a message will be displayed.

php.exe -m

If you get the following error message:

The program can't start because MSVCP100.dll is missing from your computer. Try reinstalling the program to fix this problem.

You will need to install Microsoft's Visual C++ 2010 Redistributable Package (x86)

Next, you will need to download and install Microsoft SQL Server 2012 Native Client (x86, x64) in order to connect to an SQL server using PHP. Once everything is installed you can create a test script that connects to a MSSQL server.