Dblib PDO over freetds resets a query query in SQL Server 2000 if another query is issued inside a query loop

So, we have a new server with

  • Debian Wheezy 32BIT
  • PHP 5.5.18
  • FreeTDS 0.91

This PHP application needs to talk to the old SQL Server 2000 server. We used the old code from our previous server (PHP 5.2 and older FreeTDS - cannot get the version). We connect to SQL Server 2000 via PDO using the dblib driver.

We experience strange behavior with the fetch function. Basically, if we issue a request during a fetch cycle on the same pdo connection object, the main request gets reset, and the next call to fetch returns false, even if there are more records to be extracted.

// 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>";
}

The same code on Windows PHP with the pdo_sqlserver driver works fine.

, fetch.

PHP .

, .

+4
1

: (PHP BUG SITE)

MSSQL (TDS), DBLIB FreeTDS. . , .

OOM .

, , PHP (5.3 ), TDS. .

+3

All Articles