RE: [PEAR] dataobjects newbie question

From: Date: Tue, 19 Oct 2004 05:11:56 +0000
Subject: RE: [PEAR] dataobjects newbie question
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-14964@lists.php.net to get a copy of this message
> -----Original Message----- > From: Justin Patrin [mailto:papercrane@gmail.com] > Sent: Monday, October 18, 2004 7:58 PM > To: Denis Gerasimov > Cc: Alexander Petri; pear-general@lists.php.net > Subject: Re: [PEAR] dataobjects newbie question > > On Mon, 18 Oct 2004 14:00:18 +0400, Denis Gerasimov > <denis.gerasimov@vekos.ru> wrote: > > > > Hello, > > > > I think that would be also a good suggestion (simplified example): > > > > class AdvancedDataObject extends DB_DataObject > > { > > > > function fetchArray($strFormat = '%s') > > { > > return $this->fetch() ? $this->toArray($strFormat) : false; > > } > > > > function fetchAllArray($strFormat = '%s') > > { > > $arrDataset = array(); > > while ($this->fetch()) { > > $arrDataset[] = $this->toArray($strFormat); > > } > > return $arrDataset; > > } > > > > } > > > > (We don't call find() since original fetch() method doesn't, so call > find() > > manually before pls) > > > > At least we don't need to call toArray() every time or write a loop for > > fetching all records to one recordset-like array. > > > > Or is there more straight ways for doing all of these? :-) > > > > Best regards, Denis Gerasimov > > Outsourcing Services Manager, > > VEKOS, Ltd. > > www.vekos.ru > > > > > > > > > -----Original Message----- > > > From: Justin Patrin [mailto:papercrane@gmail.com] > > > Sent: Monday, October 18, 2004 10:38 AM > > > To: Alexander Petri > > > Cc: pear-general@lists.php.net > > > Subject: Re: [PEAR] dataobjects newbie question > > > > > > On Sun, 17 Oct 2004 11:28:33 +0200, Alexander Petri > <alex.petri@gmx.de> > > > wrote: > > > > Hi! > > > > how can i select the whole table with dataobject... > > > > i chose this way: > > > > > > > > $firma = DB_DataObject::factory('crm_firmen'); > > > > $firma->query("SELECT * FROM {$firma->__table} "); > > > > while ($firma->fetch()) { > > > > $rs[]= $firma->toArray(); > > > > } > > > > > > > > but isnt there a better way to selectAll > > > > isnt there a method to do this? > > > > > > > > > > $firma = DB_DataObject::factory('crm_firmen'); > > > if ($firma->find()) { > > > while ($firma->fetch()) { > > > $rs[]= clone($firma); > > > } > > > } > > > > > > -- > > > paperCrane --Justin Patrin-- > > > > > DB_DataObject is supposed to get you away from the array way of doing > things and also tries to keep you from having to have all of the > records in memory at once. It's must better to deal with the data as > you're fetching it from the DB than to do a getAll. > > -- > paperCrane --Justin Patrin-- > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php Well, I can agree with you. The only reason why we use this is passing data to Smarty templates. In this case we have to fetch all data (and have all records in memory) anyway... Is there a better way to deal with this? e.g.: <?php require_once 'usdmari.class.php'; // uses factory() method $objStatistics = WebApplication_USDMari::createDataObject('statistics'); $objStatistics->selectAdd('description, file'); $objStatistics->find(); $arrStatisticsResult = $objStatistics->fetchAllArray(); $objSmarty = WebApplication_USDMari::createSmarty(); $objSmarty->assign('arrStatisticsResult', $arrStatisticsResult); $objSmarty->display('practice/statistics.tpl.html'); ?> Thanks. Best regards, Denis Gerasimov Outsourcing Services Manager, VEKOS, Ltd. www.vekos.ru

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