php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38861 PDO retrive no mysql-results when using the same variable
Submitted: 2006-09-17 17:11 UTC Modified: 2006-12-03 23:32 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Drezil at web dot de Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.6 OS: Debian/Sarge
Private report: No CVE-ID: None
 [2006-09-17 17:11 UTC] Drezil at web dot de
Description:
------------
with update to php 5.1.6 i ran into problems with the pdo-mysql module (loaded as dyn. extension in the php.ini).
If i reuse a variable after retrieving a mysql-result any following result is empty although the query (as shown in the mysql-log) is ommited correctly and has valid results.

switching mysql 4.1.15 to mysql 5.0.x or the oter way round doesn't fix anything.

Reproduce code:
---------------
<?php
$user = 'xxx';
$pass = 'xxx';
try {
   $dbh = new PDO('mysql:host=localhost;dbname=xxx', $user, $pass);
   $qry = $dbh->query('SELECT 1+1')
   echo '\''.print($qry->fetch(PDO::FETCH_NUM),true).'\'<br />';
   $qry->closeCursor();
   $qry = $dbh->query('SELECT 1+1')
   echo '\''.print($qry->fetch(PDO::FETCH_NUM),true).'\'<br />';
   $qry->closeCursor();
   $qry = $dbh->query('SELECT 1+1')
   echo '\''.print($qry->fetch(PDO::FETCH_NUM),true).'\'<br />';
   $qry->closeCursor();
} catch (PDOException $e) {
   print "Error!: " . $e->getMessage() . "<br/>";
   die();
}
?> 

Expected result:
----------------
'2'<br />
'2'<br />
'2'<br />

Actual result:
--------------
'2'<br />
''<br />
''<br />

if i just rename the objects to $qry1, $qry2, $qry3 everything works fine and as expected.
looks like closeCursor() deosn't work right or the objects are not overwritten correctly.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-19 16:49 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You either need to enable buffered queries or disabled native 
prepare for this to work. Or replace closeCursor() with unset
($qry).

The issue is actually a MySQL limitation with buffered 
queries.
 [2006-09-19 18:49 UTC] Drezil at web dot de
This is definitely a bug in PDO. I tried unset($qry);, a "$qry = null;" and so on and so forth.
the exact same code actually works in my other enviroment (WinXP, IIS5, PHP 5.0.7, Mysql 4.1.15). I also un-/reinstall php on the debian system.

To get it even more confusing i got such constructs in other scripts, which work as the should.
as shown in the mysql-log the prepare and the execute is omitted correctly. even $qry->rowCount(); echos '1'.. but still $qry->fetch() returns false.

by the way: a buffered-query problem in not solved by just renaming the var's (because if an unbuffered qry is sent, it must be closed explicitly before reusing the same connection. this does't depend on the var-name in php). This would just raise an error during script execution (which is printed to me due to an error-level of E_ALL | E_STRICT).

my script is quite complex, so i reduced the example to the minimum. A more detailed view on the source-code can be fond at: http://vserver.mission-unknown.de/stuff/code.phps

if this is no bug, WHY does the EXACT SAME script behave completely different on both systems? The differences in the php.ini are only system-specific due to win/unix reasons so there is no "misconfigured"-excuse.

Sorry to cause you so much trouble.. ;)
 [2006-12-03 23:32 UTC] iliaa@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC