At 12:20 PM 1/29/2006, daniel smith wrote:
I am playing around with Mysql and php and I am not sure about when it is best do something in mysql or php when BOTH can perform the operation. Example, date formating can be performed by Mysql during the query DATE_FORMAT(blah, blah...) or by php with date(blah, blah..). What are the upsides/downsides of doing something like this in Mysql/php. My current (though limited) thinking is not much improvement in either approach over the other in both operations are performed by the same server. I can only see a difference when using huge databases and the database is on a different machine. What is considered to be "Best practise" when Mysql and php can perform the same operation?
Thinking about it, if you're retrieving data, manipulating it during the fetch makes more sense than retrieving it, then manipulating it afterwards. Other than that, all you can do is run some tests - reformatting dates, or string replacements, are not operations which are among the primary functions of database engines.
So there's no best practise, except to normalize your data, optimize your database, and use appropriate indexes.
Most likely, processing differences are insignificant. In that case the best practice would be whatever results in clearer code, code you can come back to in six months and quickly grasp its sense.
Cheers - Miles -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.375 / Virus Database: 267.14.23/243 - Release Date: 1/27/2006 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php