Is it better to return a multi-array, or an array of objects?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm building a fairly large project. I've been trying to follow best
practices, but I'm a bit worried about performance. Using PHP 5.1 and mySQL
5.0.

I have product and company classes.

So when a user does a search of the database, is it better/faster/etc. to
return just a two dimensional associative array to populate an HTML table of
the results like: product name, product id, price, company name, company
phone, etc. (assume I'm only showing some of the total number of fields).

Or, should my SQL method return me an array of product objects, which then
inturn contain a company object? Keeping in mind, these objects are then a
complete snapshot of the database row they represent, along with other
fields and such that are created upon instantiation.

Does this make sense what I'm asking?

Are these things negligible?

Does it matter that I'm only showing say 10 fields of perhaps 50 or more
possible ones (that the classes and database would hold)?

My gut feeling is to use an array as it seems less overhead and "faster".
However the object versions seems to be more expandable and maintainable
perhaps. Although a bit more work due to all the method calls to pull out
the stuff to display in the HTML.

I could run timing tests, etc, but I only have like 10 products right now in
the database while I'm building, and without REAL world data, I think my
tests will be skewed.

Lets say that I expect several thousands to a hundred thousand or so people
searching the database via the web UI when this is finally completed.

ÐÆ5ÏÐ 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux