Re: PEAR::DB Question about array

From: Date: Thu, 14 Apr 2005 16:20:55 +0000
Subject: Re: PEAR::DB Question about array
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18755@lists.php.net to get a copy of this message
On 4/14/05, Massimiliano Arione <garak@studenti.it> wrote: > Justin Patrin wrote: > > [snip] > > $recs = $db->getAll('SELECT * FROM table', DB_FETCHMODE_ASSOC); > > > > However, this isn't a great way to do things unless you absolutely > > *have* to have all of the data. It's better to do: > > > > $sth = $db->query('SELECT * FROM table'); > > while ($rec = $sth->fetchRow(DB_FETCHMODE_ASSOC)) { > > //process $rec > > echo $rec['field'].'<br/>'; > > } > > Just curious: why do you think this? > Doesn't getAll() do exactcly the same (fetching data in a while loop and > putting it in array) for you? > Yes, however I wasn't suggesting that. I was suggesting processing the data *inside* the loop instead of putting it all into an array. Putting all of the records in an array just takes up more memory, it's better to use what you need and let the memory be reclaimed instead of keeping it all in memory. -- Justin Patrin

« previous php.pear.general (#18755) next »