0

I've been trying to connect to my Azure SQL database using PHP 7.1. I've been following Microsoft's instructions so I'm using the iis express. After browsing and following the directions from posts like "Call to undefined function sqlsrv_connect()" when trying to connect to Azure DB from PHP and Cannot Call function sqlsrv_connect(), I still cannot connect.

<?php
    $serverName = "database_name.database.windows.net";
    $connectionOptions = array("Database" => "database_name");
    try {
        $conn = sqlsrv_connect($serverName, $connectionOptions);    
    } catch (Exception $e) {
        print_r($e);
    }
?>

Here are the solutions I've tried:

  • Installed all the necessary SQL drivers
  • Reconfigured the php.ini file with the extensions and correct extension path
  • Ran PHP as an administrator from the PHP folder and also from another folder using its %PATH%
  • Restarted several times
  • Connected successfully to the database from the CMD line

This is my first time using PHP to connect to a remote SQL server so any help would be greatly appreciated.

1 Answers1

0

You need to check whether your drivers match the PHP Version, Architecture (32/64 bits) and Thread Safety you are using.

For example, if you are using x86 and thread-safe version of PHP 7 then the following DLLs should be used:

extension=php_sqlsrv_7_nts_x86.dll
extension=php_pdo_sqlsrv_7_nts_x86.dll

You can see these PHP info via phpinfo() function:

enter image description here

Aaron Chen
  • 9,835
  • 1
  • 16
  • 28