Connect with us

PHP

How To Connect PHP to Microsoft SQL Server

Tisna Adinata

Published

on

How To Connect PHP to Microsoft SQL Server

Hi Guys, welcome back to codingofcents.com. Today we will learn how to connect PHP to Microsoft SQL Server with ODBC Driver.

To connect PHP to Microsoft SQL Server is need more effort and motivation because we need to install Microsoft ODBC driver and also PHP sqlsrv driver.

Prerequisite

To follow this tutorial, you need to install PHP, Microsoft ODBC Driver, and PHP Sqlsrv driver. You can read full System Requirements for the Microsoft Drivers for PHP for SQL Server in this link.

In this tutorial, I will use PHP 7.2.11 which include when I install Laragon local server (similar to xampp) and Microsoft ODBC Driver 13. You can download them by clicking links below:

Installation

After download software that we need, then we can install them

  1. Install Laragon

    First, we must install the local server to serve our PHP application to make our application run properly. You can find the installation process in my previous post

  2. Install SQL Server ODBC Driver

    Double click the Microsoft ODBC Driver for SQL Server installation file version which sustainable with your windows version (32/64 bit) then click next.How To Connect PHP to Microsoft SQL Server

  3. Install SQL Server ODBC Driver Step 2

    Click Next
    How To Connect PHP to Microsoft SQL Server

  4. Install SQL Server ODBC Driver Step 3

    Click install
    How To Connect PHP to Microsoft SQL Server

  5. Install SQL Server ODBC Driver Step 3

    Wait for installation
    How To Connect PHP to Microsoft SQL Server

  6. Install SQL Server ODBC Driver Step 4

    Finish Installation
    How To Connect PHP to Microsoft SQL Server

  7. Install Microsoft driver for PHP for SQL Server

    After install ODBC driver now we need to install driver PHP for SQL Server which downloaded previously. Double click the installation file and click Yes
    How To Connect PHP to Microsoft SQL Server

  8. Install Microsoft driver for PHP for SQL Server Step 2

    Click Browse to decide where you want to place the extracted files. Then click OK. After that
    How To Connect PHP to Microsoft SQL Server

  9. Copy .DDL file

    After the file is extracted, copy two files below to extension folder where your PHP installed. For example C:\laragon\bin\php\php-7.2.11-Win32-VC15-x64\ext.How To Connect PHP to Microsoft SQL Server

  10. Edit php.ini file

    After copy PHP extension folder, we need to edit our php.ini file to active the extension. I just rename the two files that had been copied. Edit php.ini by add to line code like below.

    extension= php_sqlsrv_72_ts.dll
    extension= php_pdo_sqlsrv_72_ts.dll

    How To Connect PHP to Microsoft SQL Server
    After that we need to restart the apache server

  11. Test the installation

    We can test the driver installation by open CMD and type php -vHow To Connect PHP to Microsoft SQL Server

  12. We can also check installation by go to http://localhost:808/?q=info

    Note: I change apache port to 808, so if you do not change the port just got to http://localhost?q=info and you get your PHP information. Search for sqlsrv. If you find it, congrats you are done this lesson. if you find an error please check back the installation process.
    How To Connect PHP to Microsoft SQL Server

Conclusion

PHP can be integrated with Microsoft SQL Server with the driver that provided by Microsoft and it not hard to install.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 4 =

Trending