Making ODBC Driver 11 for SQL Server Available For PHP In Azure Website

I have a PHP 5.5 website running WordPress in Azure Websites configured to run with 64-bit IIS, with the database running in MySQL. I want to convert the site to use SQL Server in Azure instead of MySQL.

I’ve installed the WP Db Abstraction plugin, and followed its setup instructions. I’ve elected to use the sqlsrv driver, so I’ve installed the Microsoft Drivers for PHP for SQL Server 3.1 and added them into a folder in the WordPress website and configured them as an extension. Calling phpinfo() on a test page shows that the sqlsrv driver has been loaded into PHP, and also reports that PHP is x86.

Read More

I’ve also setup the database, user and password and tested that I can connect to it successfully using SQLCMD.

The Microsoft Drivers for PHP for SQL Server 3.1 instructions state that the “Microsoft ODBC Driver 11 for SQL Server version 11” is also required. I’ve downloaded the x64 and x86 versions and tried the DLLs out of the relevant Windows directories and added them to the extension directory alongside the PHP drivers for both architectures but neither has worked.

When trying to connect to the SQL Azure Database from the running PHP site, I just get this error:

This extension requires the ODBC Driver 11 for SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712

The DLL files for the drivers I have relative to the WordPress site root are:

  • extmsodbcsql11.dll
  • extphp_sqlsrv_55_nts.dll
  • ext1033msodbcsqlr11.rll

I have the following set in the Azure Management Portal for the website for the App Settings:

PHP_EXTENSIONS:extphp_sqlsrv_55_nts.dll

All I can figure is that I’m either missing something from the ODBC drivers, or how I’m going about making them available to the PHP driver is incorrect.

Does anyone have any ideas as to what I’ve missed, or why this isn’t working?

Below is the test code I’m using to test the SQL Server connectivity in PHP.

<?php
$serverName = "MYSERVER.database.windows.net,1433";
$connOptions = array("UID"=>"MYUSERNAME", "PWD"=>"MYPASSWORD");
$conn = sqlsrv_connect( $serverName, $connOptions );

if( $conn === false ) {
    die( print_r( sqlsrv_errors(), true));
}

if( $client_info = sqlsrv_client_info( $conn)) {
    foreach( $client_info as $key => $value) {
        echo $key.": ".$value."<br />";
    }
} else {
    echo "Error in retrieving client info.<br />";
}
?>

Related posts

Leave a Reply

1 comment

  1. I didn’t really find a proper solution to this in the end, but it turned out that all the bits for using SQL Server with PHP 5.4 are already installed in Azure Websites.

    I downgraded from PHP 5.5 to 5.4 and then SQL Server connectivity started working.

    Not really a fix, but it’s gotten me to the position (mostly) that I wanted.