Connect to SQL server in PHP

Madhawa Manchanayake
2 min readMay 1, 2019

Here I will explain how to simply connect Microsoft SQL server in php. For this tutorial, I am using XAMP and Microsoft SQL server 2017.

There are two main authentication methods in SQL server, If you are a student you are probably using Windows authentication and the other one is using a username and password.

Firstly let’s look at how to connect using windows authentication. for this, you need to have Microsoft ODBC driver for SQL server installed in your PC. You can download it from the link given below.
Microsoft ODBC driver for sql server: https://www.microsoft.com/en-in/downl...

Then start you apache server from XAMPP

XAMPP control ppanelThen check your PHP version. you can access that data using something similar to this URL: http://localhost:8080/dashboard/phpinfo.php
Find the PHP version and architecture

Then go to the provided GitHub repo and download the DLL file related to your PHP version and operating system that you use.

Go to Link for php7 drivers: https://github.com/Microsoft/msphpsql...

Download the DLL

Extract the folder and copy the following files from
Windows-7.3\Windows-7.3\x64 to C:\xampp\php\ext

Copy these files

Then open the apache control panel and open the config file and add the following lines in the extension area.

extension=php_pdo_sqlsrv_73_ts
extension=php_sqlsrv_73_ts

Restart the apache server, then use the following code to connect to Microsoft SQL server

ServerName can be found here.

--

--