[clue-tech] PHP/MySQL question

Greg Knaddison greg.knaddison at gmail.com
Fri Sep 23 18:39:15 MDT 2005


On 9/22/05, Jeff Schroeder <jeff at neobox.net> wrote:
>
> My general feeling is that stuff like this should be handled by the
> programming language and not the database.  When I write applications I
> work hard to keep them database-neutral, because every now and then a
> client will want to port the system to their shiny new database server
> (corporate policy or whatever) and if you have to hunt through all your
> source code to find queries specific to, say, MySQL and convert them
> to, say, SQL Server... well, that's no fun.

This is an important point, but...

>
> Sure, it'll be slightly faster to do it in the database than to load the
> results into PHP and do some sort magic.  But you can do more advanced
> sorting and manipulation programmatically than you can in SQL-- if it
> ever comes to that-- and I'd wager that if you timed the two approaches
> you'd see things like 0.02 seconds versus 0.04 seconds or something.
> These days, performance between a database and web app is blazingly
> fast so optimizing stuff like this is simply not worth the trouble.
> (That being said, complicated queries and joins between hundreds of
> thousands of records should *never* be done programmatically!)
>

Heh.  Try explaining that join business to the last company I worked
for (sorry, Brad!).

I'm not sure I agree with your comment that PHP would allow for more
advanced sorting...Databases do a few things _really_ well and one of
those is sorting.  And .02 vs. .04 can be a big deal when you do it
1000 times a day or when you have 100 users doing it 1000 times a day.

To pose a similar question, what if you wanted to migrate this code to
an ASP or ColdFusion only environment that didn't care which database
- then you'd be happy to have more logic in the DB.  I'm not sure
which is more likely, but I've dealt with both points of view in a
pretty short career.

> The bottom line, though, is that it probably doesn't matter much either
> way.  Do whatever you're comfortable doing, because both approaches
> will work.
>

Yeah, that's the ticket, really.  I feel much more confident that I
can edit a few lines of sql so I tend to do whatever I can to push
logic into database-land.

Greg
_______________________________________________
CLUE-tech mailing list
CLUE-tech at cluedenver.org
http://cluedenver.org/mailman/listinfo/clue-tech



More information about the clue-tech mailing list