Problem in DB_result::free()
| From: | Jon Parise | Date: | Sat, 01 Jul 2000 02:56:19 +0000 |
| Subject: | Problem in DB_result::free() | ||
| Groups: | php.pear | ||
| Request: | Send a blank email to php-pear+get-129@lists.php.net to get a copy of this message | ||
I just ran into a nasty little bug in DB_result::free(). This took me
forever to track down, but I think I found the problem and the
solution.
Here's some code snippets from a class I'm working on:
$this->db = &DB::connect($this->params, true);
$query = "select * from foo";
$result = $this->db->query($query);
if (isset($result)) {
$row = $result->fetchRow();
if ($row && ($row[0] == '1')) {
$result->free();
return true;
}
$result->free();
}
Alright, that's pretty much all that's relevant. Now, from what I
could tell, this code would work the first time through and fail
fatally each time thereafter with a "Can't invoke method from
non-object" kind of error on the $this->db->query() line.
I eventually tracked the problem back to the $result->free() calls. I
didn't see how that was affecting the $this->db class (DB_result is
its own class, afterall) until I looked closer at the DB_result::free()
method:
function free() {
$err = $this->dbh->freeResult($this->result);
if (DB::isError($err)) {
return $err;
}
$this->dbh = $this->result = false;
return true;
}
Well, apparently, when it sets $this->dbh = false, it ends up
following the reference all the way back to my class and kills my
database handle. Well, that's super.
Removing '$this->dbh' from that line makes everything work happily.
Am I misinterpretting something here? Is this really a bug or the
intended behavior? I figure it's generally safe to free result sets
all I want without it affected my database handle.
--
Jon Parise (jon@csh.rit.edu) . Rochester Inst. of Technology
http://www.csh.rit.edu/~jon/ : Computer Science House
Member