php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64328 No results when re-executing PDO dblib query using same variable
Submitted: 2013-03-01 01:18 UTC Modified: 2013-05-31 21:44 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: brad at wcubed dot net Assigned: ssufficool (profile)
Status: Closed Package: PDO related
PHP Version: 5.4.12 OS: FreeBSD 9.1 amd64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: brad at wcubed dot net
New email:
PHP Version: OS:

 

 [2013-03-01 01:18 UTC] brad at wcubed dot net
Description:
------------
Environment:

MS SQL Server 2008 R2
FreeTSD 0.64_9,1

No results are returned from dblib PDO::query() + PDOStatement::fetchAll() if the same variable is re-used from a previous query/fetch.

If the variable is unset() before the second query, the behavior is as expected.

This problem is reproducible on both a fresh install of FreeBSD 9.1 and longstanding 8.2 install. This behavior was not evident on the FreeBSD 8.2 install prior to a php upgrade from 5.3.8 to 5.4.12.

Test script:
---------------
$dbh = new PDO("dblib:host=$host;dbname=$dbname", $user, $pass);

$create = $dbh->exec('DROP TABLE foo');
$create = $dbh->exec('CREATE TABLE foo (ID int PRIMARY KEY IDENTITY (1,1) NOT NULL, bar VARCHAR(10))');
$insert = $dbh->exec('INSERT INTO foo (bar) VALUES (\'baz\')');

$qry = 'select * from foo';

$stmt = $dbh->query($qry);
$results = $stmt->fetchAll(PDO::FETCH_NUM);
print_r($results);

$stmt = $dbh->query($qry);
$results = $stmt->fetchAll(PDO::FETCH_NUM);
print_r($results);

unset($stmt);
$stmt = $dbh->query($qry);
$results = $stmt->fetchAll(PDO::FETCH_NUM);
print_r($results);

Expected result:
----------------
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => baz
        )

)
Array
(
)
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => baz
        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => baz
        )

)
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => baz
        )

)
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => baz
        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-01 03:56 UTC] brad at wcubed dot net
Reverse the expected and actual results. The second fetchAll() returns an empty array.
 [2013-05-31 21:44 UTC] ssufficool@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ssufficool
 [2013-05-31 21:44 UTC] ssufficool@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Duplicate of BUG #64522
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 28 07:01:27 2024 UTC