duanpeng1532 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:

PHP_EXTENSIONS:ext\php_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 />";
}
?>
  • 写回答

1条回答 默认 最新

  • duanlaiquan8174 2015-02-09 18:45
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能