Re: Re: What about DB_FETCHMODE_OBJECT in PEAR/DB.php?

From: Date: Thu, 02 Aug 2001 13:11:50 +0000
Subject: Re: Re: What about DB_FETCHMODE_OBJECT in PEAR/DB.php?
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-1237@lists.php.net to get a copy of this message
"Tomas V.V.Cox" wrote: > > "Stig S. Bakken" wrote: > > > > "Tomas V.V.Cox" wrote: > > > > > > Philip Hallstrom wrote: > > > > > > > > Hi - > > > > I was wondering why there isn't the option to fetch rows as > > > > objects in DB.php and friends? It doesn't look like it would be that hard > > > > to add... and I will if you want me to send you the patches... > > > > > > Other times this feature was suggested but always were rejected :) It's > > > true that doesn't seem to be very problematic to implement. Perhaps due > > > the amount of request we could re-think this matter. What do you thing > > > Stig? > > > > Sure, let's add DB_FETCHMODE_OBJECT. It'd still be cool to be able to > > specify which class the object should use (instead of the dumb > > "StdClass" you get when casting). > > > > Umm.. perhaps we could extend the IMHO no very useful idea of fetching > objects and provide something new. For example methods: > > $row->type('id'); > $row->numFields(); > $row->toFile('data'); > > I'll start to look at integrating the new fetchmode. > After some researching, I find a way of doing what we wanted. Something like this in DB_result::fetchrow(): $arr = $this->fetchRow(DB_FETCHMODE_ASSOC); // a new class DB_row we can improve as long as we want $row_obj = &new DB_row; for (reset($arr); $key = key($arr); next($arr)) { $row_obj->$key = &$arr[$key]; } // this code will be encapsulated inside the $row_obj // $row_obj = &new DB_row($arr). return &row_obj; What do you think about the loose of performance between this and a cast? As in PHP we don't have yet: foreach($arr as $key => &$value) the code needs to be more ugly :) If no more ideas I'll start to work in this direction. Tomas V.V.Cox

« previous php.pear.dev (#1237) next »