Context:
- We have a PHP/MySQL application.
- Some portions of the calculations are done in SQL directly. eg: All users created in the last 24 hours would be returned via an SQL query ( NOW() – 1 day)
There's a debate going on between a fellow developer and me where I'm having the opinion that we should:
A. Keep all calculations / code / logic in PHP and treat MySQL as a 'dumb' repository of information
His opinion:
B. Do a mix and match depending on whats easier / faster. http://www.onextrapixel.com/2010/06/23/mysql-has-functions-part-5-php-vs-mysql-performance/
I'm looking at maintainability point-of-view. He's looking at speed (which as the article points out, some operations are faster in MySQL).
@bob-the-destroyer @tekretic @OMG Ponies @mu is too short @Tudor Constantin @tandu @Harley
I agree (and quite obviously) efficient WHERE clauses belong in the SQL level. However, what about examples like:
- Calculating a 24 period using NOW() - 1 day in SQL to select all users created in last 24 hours?
- Return capitalized first name and last name of all users?
- Concatenating a string?
- (thoughts, folks?)
Clear examples belonging in the SQL domain:
- specific WHERE selections
- Nested SQL statements
- Ordering / Sorting
- Selecting DISTINCT items
- Counting rows / items