Re: [PHP] Getting mysql_query results into an array
- From: ceo@xxxxxxxxx ("Richard Lynch")
- Date: Wed, 14 Feb 2007 18:06:16 -0600 (CST)
On Tue, February 13, 2007 8:22 pm, Robert Cummings wrote:
On Tue, 2007-02-13 at 18:22 -0600, Richard Lynch wrote:
#2
loop through mysql result set to build $array
perform some kind of calculation upon $array
In this case, it's USUALLY much more efficient to write an SQL query
to perform the calculation.
Databases are highly optimized for this kind of thing, and very
efficient at it.
PHP is a generalized programming language, and not so efficient for
this kind of task.
#2 does occasionally have an exception to the rule, where the SQL
query is nasty and the PHP is fast and easy, but that's awfully
rare.
I hear this all the time that the database should do as much as
possible
"it's highly optimized" yadda yadda. I'm going to go out on a limb and
say that in a heavily loaded system, shoving all the work into the
primary bottleneck is a bad idea. 100 workers make light work, and
that
would be the inherent power in horizontal scalability. Databases do
not
scale well horizontally, machines loaded with Apache and PHP do,
especially when each machine doesn't expect the database server to do
all the work. In fact, I'd wager queries involving joins are another
bane on horizontal scalability since now the tables are forced to
reside
on the same machine.
I could be completely wrong, I've never worked on an extremely loaded
server, but I get a tick every time someone says "shove all the work
into the query", and that usually happens when something doesn't feel
right :)
For the 0.1% of people who can't get enough performance out of their
web farm and "single" DB, there are several interesting possibilities
for factoring or distributed processing, including scaling
horizontally with PHP but they also can consider segmenting the DB in
various ways, or even replacing the DB with something faster/lighter
or something that scales horizontally for the most-used functionality
(e.g., MCache for session management).
The "right" answer for that 0.1% isn't gonna be covered in a 10-second
answer on PHP-General, though, as it's almost-for-sure going to depend
on their application needs more than any off-the-rack answer.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.
- References:
- Getting mysql_query results into an array
- From: Skip Evans
- Re: [PHP] Getting mysql_query results into an array
- From: "Richard Lynch"
- Re: [PHP] Getting mysql_query results into an array
- From: Robert Cummings
- Getting mysql_query results into an array
- Prev by Date: Re: [PHP] Object ID
- Next by Date: Re: [PHP] Object ID
- Previous by thread: Re: [PHP] Getting mysql_query results into an array
- Next by thread: Re: [PHP] Getting mysql_query results into an array
- Index(es):