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 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.