I get a lot of forum posting in our IIS forum asking how to develop PHP application using Microsoft SQL Server. Today I am going to explain basics of developing PHP application on Microsoft SQL Server. Let me start by stating one thing, developing PHP application on Microsoft SQL Server is really easy. The extension which glues the two world namely PHP and Microsoft SQL Server is called ‘Microsoft SQL Server Driver for PHP’. Some important characteristics of this driver are:
- This is fully supported by Microsoft (so far as you are using the binaries distributed by Microsoft).
- The 1.1 release of the driver supports both PHP 5.2 (to be precise PHP version 5.2.4 onwards) as well as PHP 5.3.
- Both thread safe and non thread safe DLL is distributed. This means one can use it on Windows hosting IIS or Apache.
- People can also look at the code of the driver. The source code for the driver is available here.
- There is support in the form of forum too. Simply post your query/question here.
- There is also a team blog which talks about new release/feature at http://blogs.msdn.com/sqlphp/.
- The manual explaining every detail can be found at http://technet.microsoft.com/en-us/library/ee229548(SQL.10).aspx.
- One can download it from http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9.
This driver is replacement of old PHP MSSQL driver. So if you have enabled this extension, you may as well disable php_mssql.dll extension in your php.ini file. In order to disable the old MSSQL driver simply comment the below line in your php.ini file (put ‘;’ in the beginning of the line).
The old MSSQL driver is not supported by Microsoft as it takes dependency on some deprecated libraries, so it is a good idea to do the new development using new SQL Server driver. Also porting your existing application to the new SQL Server driver should be easy and is advisable from my side unless you are not planning any enhancement/development in that piece of code.
One can use Microsoft Web Platform Installer too to get the latest driver. The SQL Server driver can be found under ‘Database’ link inside ‘Web Platform’ tab. The installation comes with different version of driver to support different version of PHP as well as thread safe and non-thread safe appetite of it. The naming convention should tell you this. For example the DLL named ‘php_sqlsrv_53_ts_vc9.dll’ means this DLL should be used with thread safe version of PHP 5.3 built using VC9 compiler. Please use appropriate version otherwise PHP will not load the DLL at runtime. The installation also comes with a help file (CHM file) which contains lot of useful information pertaining to installation, usage as well as all the API well documented.
I hope this will help you getting started with developing PHP application on Microsoft SQL Server. Thanks for the patient reading and till we meet again ‘Good Bye’.