Re: 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]

 



On 4/03/2006 3:10 PM, Daevid Vincent wrote:
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).
[snip]

One observation: you shouldn't return all fields in a recordset unless you *need* all of the fields in a recordset.

The majority of the time, you should be explicitly stating which fields to retrieve in your SQL statement, as in:

SELECT field1, field2, field8 FROM mytable WHERE <whatever>

as opposed to:

SELECT * FROM mytable WHERE <whatever>

Some of the time, yes, that will mean you're explicitly typing out 7 field names from a table that only has 8 field names, but getting out of the habit of using "*", particularly if you expect your application to work well under heavy loads, will save you resources, which will increase your app's overall performance.

It may be you're already doing this, but it wasn't clear from your post.

Much warmth,

planetthoughtful
---
"Lost in thought"
http://www.planetthoughtful.org

--
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