What's faster? MySQL Queries or PHP Loops?
| From: | Robb Kerr | Date: | Wed, 08 Sep 2004 15:22:15 +0000 |
| Subject: | What's faster? MySQL Queries or PHP Loops? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-196135@lists.php.net to get a copy of this message | ||
Here's the scenario...
First, my HTTP Server (Apache), PHP Server and MySQL Server are on the same
machine - an Apple Xserve.
Second, I've got a page with a long repeat region reflecting a recordset
queried out of a MySQL table. The region also displays information obtained
from fields in a related table.
Third, I use Dreamweaver to generate my MySQL recordsets and repeat
regions.
Here's the question...
I can either A) in the header or my page, generate a recordset of all of
the records in the related table and then loop through the recordset
creating an array of the fields I need and then later pull from it in the
repeat region... or B) take the six lines of code Dreamweaver generates to
create a recordset and move them into the repeat region itself. In other
words, I can create a recordset of all of the records in the related table,
loop through it generating a PHP array and pull from this array later OR I
can query the database every time through the loop while creating the
repeat region.
Since I haven't freed the table until the bottom of the page and because my
MySQL Sever and PHP Server reside on the same machine, will I really notice
a measurable difference in speed? If my MySQL Server were a different
machine, I'm sure that there would be a noticable difference because all of
the queries would be across a network (possibly the internet) and traffic
would become a factor.
Just wondering what other people have noticed.
--
Robb Kerr
Digital IGUANA
Helping Digital Artists Achieve their Dreams
----------------------------------------------------
http://www.digitaliguana.com
http://www.cancerreallysucks.org