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 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值