How to enable MS SQL server access in php?

The Microsoft Drivers for PHP are the PHP extensions that allow for the reading and writing of SQL server data from PHP scripts. To enable it, we will need to add two extensions in PHP. The SQLSRV extension provides a procedural interface, while the PDO_SQLSRV extension implements PDO for accessing data in all editions of SQL Server 2008 and later. Please follow the below steps to enable it.

To check the compatible version of MS SQL drivers for your PHP, click here.
1. Log in to your Windows VPS via RDP (Remote Desktop Access). This tutorial will guide you to connect to a Windows VPS server using the RDP from different operating systems.

2. To download the drivers for PHP, click here. Select the appropriate version and click Next.

Note: As we are using PHP 5.6, we have downloaded version 3.2.

Download MS SQL Drivers For PHP

3. It will prompt you to save the exe file. Click on Save File.

Extract Files

4. Once the drivers are downloaded, run the exe file. It will ask for the path to extract. Provide the path and click on Ok.

Provide Path For File Extraction

5. Go to the extracted folder and copy the NTS (for Windows) dll files to the PHP extension folder.

Note: As we are using PHP 5.6, we have copied the files to C:\Program Files (x86)\PHP\v5.6\ext


Copy Files to PHP Extension Folder

6. Once the files are copied, we need to add the following extension in the php.ini file.


Add DLL Files in Php.ini

7. Create a phpinfo file and check if the extensions are shown properly. To create a phpinfo file, follow the instructions here.

Check Extension sqlsrv In Phpinfo

Check Extension pdo_sqlsrv In Phpinfo

That's it. Now you will be able to access the MS SQL database from PHP.

Was this answer helpful?

« Back