For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > June 2004 > Result Set Destroyed Prematurely









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Result Set Destroyed Prematurely
Derek Battams

2004-06-29, 3:56 am

I'm looping through a result set as follows:

$res = $d->query($select);

if (DB::isError($res)) {
throw new DBException(DB_QUERY_ERR, $res->getCode(), $res);
}

while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
$requests[] = Request::getInstance($row['ID']);

The result set has 18 rows and therefore I'd expect 18 iterations through
the while loop. However, using the written code I'm only getting one
iteration and then the loop breaks. I've isolated the problem to the fact
that the static method getInstance() also creates a database connection
(to the same database), does a select, builds an object, disconnects from
the DB then returns the object. If I comment out the disconnect call in
getInstance() then the loop goes around 18 times as expected. So the
problem appears to be that disconnecting one database connection
invalidates/kills the result set of another database connection. From
what I can tell, each call to DB::connect() is returning a new, unique
object so I'm not sure why the result set from one connection is being
killed when another connection is disconnected. Am I using something
incorrectly with PEAR DB?

PHP5RC3 with latest PEAR DB installed on Linux.

Help appreciated,

Derek
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com