Re: DB problem
| From: | Christopher Scollo | Date: | Tue, 18 Jun 2002 10:08:20 +0000 |
| Subject: | Re: DB problem | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1700@lists.php.net to get a copy of this message | ||
Hi,
Your result set's "pointer" is already at the end.
May I recommend that you use getAll() or getAssoc()?
http://pear.php.net/manual/en/core.db.getall.php
It's faster and simpler.
Also, don't forget your error checking! Any of these PEAR methods might return a PEAR_Error
object!
-- CS
On Tue, 18 Jun 2002, Birgir Stefansson wrote:
> Hi.
> I'm running into some problems with porting my project from using php's
> postgres functions to using the PEAR DB package. The thing is that I'm
> passing a resultset into functions and having it read in several places
> and now using the DB package I don't get the same result as with using
> the postgres calls. Doing the first reading of the whole result set
> works fine .. but doing a second one it seems that the result set has
> been emptied. A simple example does somewhat what I'm doing
>
> $res = $db->query("select name, home from acct where username='biggs'");
> while($user = $res->fetchRow()) {
> echo $user['name'] ."
> ".$user['home]."<br>";
> }
>
> while($user = $res->fetchRow()) {
> echo $user['name'] ."
> ".$user['home]."<br>";
> }
>
> The first while() works fine and I get the expected output, a single
> line. Now I was expecting the second while() to print out the same
> result, but for some reason there seem to be no rows in $res when the
> second while executes.
> Can anyone tell me what the problem is and how to go-around it ?
>
> Birgir Stefansson
>