2015-02-09 03:05
浏览 96

在Azure网站中为PHP提供适用于SQL Server的ODBC驱动程序11

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.

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:

  • ext\msodbcsql11.dll
  • ext\php_sqlsrv_55_nts.dll
  • ext\1033\msodbcsqlr11.rll

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


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.

$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 />";
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题