php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45951 PDO_MSSQL problem if query return no result
Submitted: 2008-08-29 17:55 UTC Modified: 2010-07-12 05:31 UTC
From: grzegorz at heex dot pl Assigned: ssufficool (profile)
Status: Closed Package: PDO related
PHP Version: 5.2.6 OS: Windows XP Sp3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: grzegorz at heex dot pl
New email:
PHP Version: OS:

 

 [2008-08-29 17:55 UTC] grzegorz at heex dot pl
Description:
------------
If PDO_MSSQL PDOStatement is called 2 times and the first returned no result than second one return strange result.

PDO_MYSQL works fine.

Tested on Apache and IIS

Reproduce code:
---------------
$pdo = new PDO("mssql:host=[host];dbname=[base]",[user],[pass]);

$sth = $pdo->prepare("SELECT id FROM sometable WHERE id=:parentId");

$sth->execute(array(':parentId'=>1));
//or
//$sth->bindValue(':parentId',1,PDO::PARAM_INT);
$res1 = $sth->fetchAll();
$sth->closeCursor();

$sth->execute(array(':parentId'=>2));
//or
//$sth->bindValue(':parentId',2,PDO::PARAM_INT);
$res2 = $sth->fetchAll();
$sth->closeCursor();

Expected result:
----------------
$res1 = array[0] //empty
$res2 = array[
  0 = array['value' => 3]
  1 = array['value' => 6]
]

Actual result:
--------------
$res1 = array[0] //empty
$res2 = array[
  0 = array['[]' => null]
  1 = array['[]' => null]
]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-29 18:02 UTC] grzegorz at heex dot pl
Statetment should be:
$sth = $pdo->prepare("SELECT value FROM sometable WHERE id=:parentId");
 [2009-04-25 15:11 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-06-11 07:56 UTC] grzegorz at heex dot pl
I couldn't connect to MSSQL so I've exchanged ntwdblib.dll (v.7.00.839) to (v.8.00.194).

No result is:
$res1 = array[0] //empty
$res2 = array[
  0 = array['[]' => null, 0 => null]
  1 = array['[]' => null, 0 => null]
]

( [] = ASCII 0x11 )

and should be:
$res2 = array[
  0 = array['value' => 3, 0 => 3]
  1 = array['value' => 6, 0 => 6]
]
 [2010-07-12 05:30 UTC] ssufficool@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ssufficool
 [2010-07-12 05:30 UTC] ssufficool@php.net
Tried to reproduce with code in trunk, returns expected results.

$db->query("create table test (id int not null primary key)");
$db->query("insert into test(id) values(2)");

$sth = $db->prepare("SELECT id FROM test WHERE id=:parentId");

$sth->execute(array(':parentId'=>1));
$res1 = $sth->fetchAll();
var_dump($res1);

$sth->execute(array(':parentId'=>2));
$res2 = $sth->fetchAll();
var_dump($res2);


array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "2"
    [0]=>
    string(1) "2"
  }
}
 [2010-07-12 05:31 UTC] ssufficool@php.net
Please try version in SVN trunk. This bug cannot be reproduced with the code in trunk,
 [2010-07-12 05:33 UTC] ssufficool at gmail dot com
Please try latest code in trunk. I cannot reproduce with the latest code.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC