首页 \ 问答 \ PHP 5.6升级后SQLSRV无法获取数据(SQLSRV Not Getting Data after PHP 5.6 Upgrade)

PHP 5.6升级后SQLSRV无法获取数据(SQLSRV Not Getting Data after PHP 5.6 Upgrade)

我有一个问题,我似乎无法包裹自己,所以SO社区似乎是个好去处!

我有3个PHP服务,它们只是从同一个DB的不同表中返回数据并将其作为json吐出。 3个服务都使用相同的精确代码和不同的select语句。 问题是我能够获取两个服务的数据,但不能获得一个服务(具有最大的数据集)。 我已经将我的资源配置从PHP 5.4到5.6匹配,但仍然没有结果。 所有这三种服务在PHP 5.4上运行良好,但在5.6升级之后,只有一种不能(同样,SAME CODE)。

我正在附上以下两项服务,以便您可以进行比较。 我已经验证了我的SQL语句,并检查了所有日志文件。 PHP显示没有错误,IIS显示200(在两个服务上完成GET)。

失败的服务

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);

工作服务

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);

编辑:我已经在机器上重新安装了PHP 5.6,并确保我的SQLSRV驱动程序已正确安装(因为它适用于其他2个!)。

在完成所有这些之后我还重新启动了IIS来验证。


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!

I've got 3 PHP services that very simply return data from different tables of the same DB and spit it out as 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. All three services work fine on PHP 5.4 but after the 5.6 upgrade, only one doesn't (again, SAME CODE).

I'm attaching both services below so that you can compare. I've verified my SQL statements, and checked all log files. PHP shows no errors and IIS shows a 200 (completed GET on both services).

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!).

I've also restarted IIS after all this to verify.


原文:https://stackoverflow.com/questions/36043893
更新时间:2022-12-06 09:12

最满意答案

我已经选择了一种相当粗略但有效的技术:在我的开发环境中,我有一个名为'environment_development'的空文件。 在我的生产环境中,我有一个名为'environment_PRODUCTION'(增加视觉强调的不同情况)。 我的gitignore文件设置为忽略这两个。

我的应用程序的前端控制器(我使用Kohana框架,但我假设CakePHP有类似的东西)检查这些文件的存在并适当地设置IN_PRODUCTION常量。 其余代码(数据库配置,错误处理等)可以检查此常量的值并根据需要更改行为。

我以前使用$ _SERVER ['SERVER_NAME']检查,但此方法具有以下优点:

  1. 即使您希望从命令行运行应用程序的某些部分,例如,作为cronjobs,当未设置$ _SERVER时,它也能正常工作。
  2. 即使您的应用在多个域上运行,它仍然有效。
  3. 它是完全明确的:如果有人检查了应用程序的另一个工作副本,那么在创建环境文件之前什么都不会起作用,因此没有(或很少)机会有人对生产数据库运行开发代码,反之亦然。

I've gone for a rather crude but effective technique: In my development environment I have an empty file called 'environment_development'. In my production environment I have one called 'environment_PRODUCTION' (different case for added visual emphasis). My gitignore file is set to ignore both of these.

The front controller of my application (I use the Kohana framework, but I'm presuming CakePHP has something similar) checks for the presence of these files and sets an IN_PRODUCTION constant appropriately. The rest of the code (database configuration, error handling etc.) can check the value of this constant and alter behaviour as required.

I used to use the $_SERVER['SERVER_NAME'] check, but this method has the following advantages:

  1. It works even if there are parts of your app you want to run from the command line, e.g., as cronjobs, when $_SERVER is not set.
  2. It works even if your app runs on multiple domains.
  3. It is entirely explicit: if someone checks out another working copy of the app, nothing will function until they create an environment file, so there's no (or very little) chance of someone running development code against the production db or vice versa.

相关问答

更多