Re: DB_DataObject - using foreach instead of while
| From: | Noel da Costa | Date: | Mon, 21 Aug 2006 18:54:10 +0000 |
| Subject: | Re: DB_DataObject - using foreach instead of while | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24933@lists.php.net to get a copy of this message | ||
On 21 Aug 2006, at 19:32, Justin Patrin wrote:
On 8/21/06, Noel da Costa <noel.dacosta@magharl.co.uk> wrote:While() has a reputation for being slower than foreach.. can't say I know anything technical about the reasons behind this. DB and DB_DataObject also has a reputation for being a comparatively slow abstraction layer - again I'm not sure this is founded, but the speed tests I'm running in my CMS indicate that displaying a page that contains a single record from the database is taking more than twice as long as displaying a page that doesn't access the database... pushes up the render time from 0.4 seconds to 1.1 second on average... I'm really looking for ways to speed up this access now, so I'm turning over every stone :) Thanks Nicholas Costa for the suggestion - however, I'm running PHP4. Anyone else found ways of optimizing DB_DataObject seek times?Hi there, The syntax examples for DB_DataObject show how to use a while loop with ->fetch() to iterate over records. Is there a way of doing this using a foreach loop instead? I'm trying to optimize speed here.How would foreach be better than while? foreach uses a copy of an array to loop over it. No, there is, of course, no way to do this as ->fetch() gets one record at a time. -- Justin Patrin