Edit report at https://pear.php.net/bugs/bug.php?id=19136&edit=1
ID: 19136
Updated by: [email protected]
Reported By: martin dot beeger at indurad dot com
-Summary: Infinite Resurcsion makes result object unuseable
+Summary: Infinite Recurcsion makes result object unuseable
Status: Open
Type: Bug
Package: MDB2
Operating System: Debian Squeeze
Package Version: 2.5.0b3
PHP Version: 5.3.7
Roadmap Versions:
New Comment:
-Summary: Infinite Resurcsion makes result object unuseable
+Summary: Infinite Recurcsion makes result object unuseable
Previous Comments:
------------------------------------------------------------------------
[2011-12-14 20:19:43] pizzard
Description:
------------
I spent 6 hours on this issue and also found a fix for it.
I an using MDB2 with pgsql and tried to just execute a simple query on
my database.
But for any query, i get a Buffered result object.
But acessing some method of it (like numRows() , gives me an
MDB2_Error.
Investigating the result object leads to the following Problem:
The object contains a reference to it at $this->result instead of the
ressource handle.
This leads to an infinite recursion and an error.
The reason for this is inside the Method mdb2->_wrapResult() of common
driver.
At line ~2570 there is
$result = new $class_name($this, $result, $limit, $offset);
Because in MDB2_Result_Common constuctor it says:
$this->result =& $result;
this assignment crashes all.
A new object is created, and saved in $result, but this contanis a
reference to result inside at $this->result now.
So $this->result is also modified from psql resource (which it should
be) to a pointer (reference) on the object itself.
Fix:
Add a $temp = $result; before this line and change it to:
$result = new $class_name($this, $temp, $limit, $offset);
Now because temp is copy of the ressource handler, it stays linked to
$this->result and all is fine.
Test script:
---------------
//you got a valid MDB2 handle in $mdb2
$res =& $mdb2->query("SELECT 1;");
echo (int)$res->numRows();
Expected result:
----------------
1
Actual result:
--------------
Warning: pg_num_rows() expects parameter 1 to be resource, object given
in my/path/MDB2/Driver/pgsql.php on line 1293
Notice: Object of class MDB2_Error could not be converted to int in
my/path/login.php on line xx
------------------------------------------------------------------------