RE: [PEAR] Trying to loop through MDB rowset -
| From: | Matt Friedman | Date: | Thu, 07 Nov 2002 19:32:09 +0000 |
| Subject: | RE: [PEAR] Trying to loop through MDB rowset - | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2662@lists.php.net to get a copy of this message | ||
Thanks very much Lucas.
Is loading up a new array with the whole result set ok (as in queryAll)?
I had actually thought that using the Resource Id instead of filling a
result set object/array was more efficient. The impression I have is
that using a result id uses less memory. What about large result sets?
This may not be a big issue - I'm just throwing it out there. But that's
actually why I was trying to avoid using queryAll if I could.
What about the ability to _not_ free the result so that you can continue
to loop through using the resource id when you use fetchRow etc...? (via
some flag or something?)
Anyway, thanks again :)
Matt Friedman
Web Applications Developer
www.SpryNewMedia.com
Phone: 416 992 5482
Email: matt@SpryNewMedia.com
> -----Original Message-----
> From: Lukas Smith [mailto:smith@dybnet.de]
> Sent: Thursday November 7, 2002 11:56 AM
> To: 'Matt Friedman'; pear-general@lists.php.net
> Subject: RE: [PEAR] Trying to loop through MDB rowset -
>
> Hi,
>
> > -----Original Message-----
> > From: Matt Friedman [mailto:matt@sprynewmedia.com]
> > Sent: Thursday, November 07, 2002 5:50 PM
> >
> > I had thought that this would work ok:
> > --------------------------------------------------
> > $sql = " SOME SQL HERE ";
> > $rs = $this->db->query($sql);
> > while( $row = $this->db->fetchRow($rs, MDB_FETCHMODE_ASSOC) ) {
> > // do something with the row info...
> > }
> > --------------------------------------------------
> >
>
> hmm i think i will put that one in a faq when i start on the peardoc2
> documentation :-)
>
> all of the fetch[One|Row|Col|All](), query[One|Row|Col|All](),
> get[One|Row|Col|All|Assoc]() free the result set immediately.
>
> Therefore after the first call to fetchRow $rs will be freed.
> What you rather want to do is this:
>
> $sql = " SOME SQL HERE ";
> $rs = $this->db->queryAll($sql);
> foreach( $rs as $row ) {
> // do something with the row info...
> }
>
> maybe some error checking as well ..
>
> regards,
> Lukas Smith
> smith@dybnet.de
> _______________________________
> DybNet Internet Solutions GbR
> Reuchlinstr. 10-11
> Gebäude 4 1.OG Raum 6 (4.1.6)
> 10553 Berlin
> Germany
> Tel. : +49 30 83 22 50 00
> Fax : +49 30 83 22 50 07
> www.dybnet.de info@dybnet.de
>