加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php – 如果在获取循环内发出另一个查询,PDO dblib over freetds将重置sql server 20

发布时间:2020-05-25 08:50:05 所属栏目:PHP 来源:互联网
导读:好的,所以我们有了一台新的服务器 Debian Wheezy 32BIT PHP 5.5.18 FreeTDS 0.91 这个PHP应用程序需要与旧的SQL Server 2000服务器通信.我们使用了以前服务器中的旧代码(PHP 5.2和更旧的FreeTDS – 无法获得该版本). 我们使用dblib驱动程序通过PDO连接到SQL S

好的,所以我们有了一台新的服务器

> Debian Wheezy 32BIT
> PHP 5.5.18
> FreeTDS 0.91

这个PHP应用程序需要与旧的SQL Server 2000服务器通信.我们使用了以前服务器中的旧代码(PHP 5.2和更旧的FreeTDS – 无法获得该版本).
我们使用dblib驱动程序通过PDO连接到SQL Server 2000.

我们在使用fetch函数时会遇到奇怪的行为.基本上,如果我们在同一个pdo连接对象的fetch循环期间发出查询,则主查询将被重置,即使仍有要提取的记录,下一个fetch调用也将返回false.

// PSEUDO CODE
// Here the main query
$q = $sql7->query("SELECT TOP 5 * FROM News ORDER BY Data Desc");
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {
    // Looping through the results
    echo "<h1>Main query</h1>";
    print_r($row);

    // Issue a query on the same pdo connection
    $subq = $sql7->query("SELECT TOP 1 * FROM News WHERE IDNews = " . $row['IDNews'] . " ");
    while ($subResult = $subq->fetch(PDO::FETCH_ASSOC)) {
        echo "<h1>Inner query</h1>";
        print_r($subResult);
    }

    // Here the main query $q->fetch(PDO::FETCH_ASSOC) will answer false on the next iteration
    // if we remove the subq,the main query loops just fine
    echo "<hr>";
}

使用pdo_sqlserver驱动程序的Windows PHP上的相同代码工作得很好.

我们作为fetch函数的参数传递的fetch类型无关紧要.

PHP不会抛出任何警告或错误.

我真的不知道这里发生了什么.

截至: reference (PHP BUG SITE)

This is the behavior of MSSQL (TDS),DBLIB and FreeTDS. One statement
per connection rule. If you initiate another statement,the previous
statement is cancelled.

The previous versions buffered the entire result set in memory leading
to OOM errors on large results sets.

因此,似乎以前版本的PHP(5.3和之前版本)不符合TDS行为.我们需要重构代码.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读