How to Install and Enable Microsoft SQL Server PDO Driver (PDO_SQLSRV) in PHP

The Microsoft SQL Server Drivers for PHP allow you to integrate and connect with the SQL server in the PHP applications. In this tutorial, we will show you how to install and enable MS SQL Server Driver for PDO in PHP.

  • First, download the driver from the official website.
  • Extract the downloaded archive and select the correct driver version for your PHP server.
    • The filename of the dll file will indicate the PHP version, threadness (ts/nts), and architecture. (You can run phpinfo() in PHP script to check the PHP version and architecture of your server.)
      For example, php_pdo_sqlsrv_74_ts_x64.dll is the 64-bit PDO_SQLSRV driver for thread-safe (ts) PHP 7.4.
  • Copy the comfortable dll library file to your PHP extension directory (php/ext/).
  • Edit your PHP server configuration file (php.ini) and add the following line to enable the pdo_sqlsrv extension.
    extension=php_pdo_sqlsrv.dll
  • Restart the PHP server and execute the following code to check whether the PDO_SQLSRV extension is installed on the server.
    <?php phpinfo(); ?>
  • If the pdo_sqlsrv extension is installed and enabled successfully, you will see the following section in your PHP info screen.
    pdo-sqlsrv-sql-server-driver-install-enable-support-php-codexworld

Now, you can connect and access the SQL server from PHP scripts.

Leave a reply

keyboard_double_arrow_up