简体   繁体   English

SQLSRV在PHP 5.6升级后未获取数据

[英]SQLSRV Not Getting Data after PHP 5.6 Upgrade

I've got a problem that I can't seem to wrap my self around so the SO community seemed like the place to go! 我有一个问题,我似乎无法解决问题,因此SO社区似乎是一个去处!

I've got 3 PHP services that very simply return data from different tables of the same DB and spit it out as json. 我有3个PHP服务,它们非常简单地从同一数据库的不同表返回数据并将其作为json吐出。 The 3 services all use the same exact code with a different select statement. 这三个服务都使用相同的精确代码,但具有不同的选择语句。 The issue is that I'm able to get my data on two of the services but not on one (which happens to have the largest data set). 问题是我可以在两个服务上获取我的数据,但不能在一个服务上获取数据(碰巧拥有最大的数据集)。 I've matched my Resource Configuration from PHP 5.4 to 5.6 and still no results. 我已经将资源配置从PHP 5.4匹配到5.6,但仍然没有结果。 All three services work fine on PHP 5.4 but after the 5.6 upgrade, only one doesn't (again, SAME CODE). 所有这三种服务都可以在PHP 5.4上正常工作,但是在5.6升级之后,只有一项没有(同样的代码)。

I'm attaching both services below so that you can compare. 我在下面附加了这两项服务,以便您进行比较。 I've verified my SQL statements, and checked all log files. 我已经验证了我的SQL语句,并检查了所有日志文件。 PHP shows no errors and IIS shows a 200 (completed GET on both services). PHP未显示错误,而IIS显示200(两个服务均已完成GET)。

FAILING SERVICE 失败服务

include "config/db.php";

$detailsConn = sqlsrv_connect($serverName, $connectionInfo);

if (!$detailsConn)
{
    die('Connection failed!');
}

do
{

    $json = array();

    $detailsSql = "SELECT * from dbo.DeviceTypeTable_Desktop LEFT JOIN dbo.IPAddresses ON dbo.DeviceTypeTable_Desktop.IPAddressId=dbo.IPAddresses.IPAddressid WHERE IsDeleted = 'false'";
    $detailsStmt = sqlsrv_query($detailsConn, $detailsSql);

    while ($row = sqlsrv_fetch_array($detailsStmt, SQLSRV_FETCH_ASSOC))
    {
        $json[] = $row;
    }

    $detailsSql = "SELECT * from dbo.DeviceTypeTable_Laptop LEFT JOIN dbo.IPAddresses ON dbo.DeviceTypeTable_Laptop.IPAddressId=dbo.IPAddresses.IPAddressid WHERE IsDeleted = 'false'";
    $detailsStmt = sqlsrv_query($detailsConn, $detailsSql);

    while ($row = sqlsrv_fetch_array($detailsStmt, SQLSRV_FETCH_ASSOC))
    {
        $json[] = $row;
    }
}

while (sqlsrv_next_result($detailsStmt));
echo json_encode($json);

sqlsrv_free_stmt($detailsStmt);
sqlsrv_close($detailsConn);

WORKING SERVICE 工作服务

include "config/db.php";

$detailsConn = sqlsrv_connect($serverName, $connectionInfo);

if (!$detailsConn)
{
    die('Connection failed!');
}

do
{
    $json = array();

    $detailsSql = "SELECT * from dbo.DeviceTypeTable_Yuma LEFT JOIN dbo.IPAddresses ON dbo.DeviceTypeTable_Yuma.IPAddressId=dbo.IPAddresses.IPAddressid WHERE IsDeleted = 'false'";
    $detailsStmt = sqlsrv_query($detailsConn, $detailsSql);

    while ($row = sqlsrv_fetch_array($detailsStmt, SQLSRV_FETCH_ASSOC))
    {
        $json[] = $row;
    }

    $detailsSql = "SELECT * from dbo.DeviceTypeTable_iPad LEFT JOIN dbo.IPAddresses ON dbo.DeviceTypeTable_iPad.IPAddressId=dbo.IPAddresses.IPAddressid WHERE IsDeleted = 'false'";
    $detailsStmt = sqlsrv_query($detailsConn, $detailsSql);

    while ($row = sqlsrv_fetch_array($detailsStmt, SQLSRV_FETCH_ASSOC))
    {
        $json[] = $row;
    }
}

while (sqlsrv_next_result($detailsStmt));
echo json_encode($json);

sqlsrv_free_stmt($detailsStmt);
sqlsrv_close($detailsConn);

EDIT: I've reinstalled PHP 5.6 on the machine and made sure that my SQLSRV driver was properly installed(as it works on 2 others!). 编辑:我已经在机器上重新安装了PHP 5.6,并确保正确安装了我的SQLSRV驱动程序(因为它可以在其他2个系统上工作!)。

I've also restarted IIS after all this to verify. 在完成所有这些操作之后,我还重新启动了IIS。

I've found my issue. 我发现了我的问题。 Apparently there was data coming from a table that was not UTF-8 encoded therefore causing one service to fail. 显然有数据来自未经UTF-8编码的表,因此导致一项服务失败。 The solution to this was to drop "CharacterSet" => "UTF-8" into the array of connection details for SQLSRV. 解决方案是将"CharacterSet" => "UTF-8"放入SQLSRV的连接详细信息数组中。 For some reason this encoding wasn't an issue on PHP 5.4 but from there on is. 由于某种原因,这种编码在PHP 5.4上不是问题,但从那以后就成为问题了。 It is however in best practice to ensure that you're dropping that encoding in the database connection details. 但是,最佳实践是确保在数据库连接详细信息中删除该编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM