PHP Classes

Listing Records

Recommend this page to a friend!

      PHP Classes blog  >  PHP Object-Relational...  >  All threads  >  Listing Records  >  (Un) Subscribe thread alerts  
Subject:Listing Records
Summary:Listing records using ORM uses a lot of resources
Messages:2
Author:Laurent Dinclaux
Date:2008-10-09 22:23:00
Update:2008-10-10 06:40:24
 

  1. Listing Records   Reply   Report abuse  
Picture of Laurent  Dinclaux Laurent Dinclaux - 2008-10-09 22:39:01
Hi,

I use ORM since a long time now, using my own library.

One big disadvantage of that approach is listing records.

$query = "Select record_id FROM table";
$stmt = $Database->prepare($query);
$stmt->execute($queryValues);

$List = array();
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {

$List[] = new Object($row['record_id'], $this->Database);

}

This code is damn slow and uses a lot of resources. The array approach of listing records is much faster.

Apart that drawback, Object-Relational Mapping is a must.


  2. Re: Listing Records   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-10-10 06:40:24 - In reply to message 1 from Laurent Dinclaux
Yes, you are right, when you just want to retrieve a few elements from objects for read-only purposes like listing data or sending newsletters, as it was mentioned in the article, retrieving whole objects is inadequate because it takes more memory and CPU to achieve.

This is something on that Metastorage excels. As described in the article it provides a solution to retrieve data from individual arbitrary object variables for read-only purposes using report classes. The data is returned as arrays like you describe. So it is much more efficient solution.