How much intelligence in the MySQL Query how much in the Code?
SQL queries provide highly efficient access to parallel data (records). Very often you can get the exact data you require with your query and then all you have to do with your code is present it. Other times it simply isn't possible or isn't convenient to do it all in the SQL. In these cases typically you download the query results into an associative array, then you can further manipulate your data at leisure with all the power of PHP, Perl etc.
What do I mean by convenient? well sometimes it might be possible to develop a complex query which drilled right down to the exact data but this might take time to perfect when you could have coded it much quicker.
What's more I have found that over-complex queries are not very future proof, by that I mean a small change in the specification and they have to be rewritten. Further more they may not be very easy for other programmers to understand/maintain.
So do the best query you can and then manipulate the data in your code.
Truism: SQL can never be so flexible as a scripting/programming language such as PHP/Perl
What do I mean by convenient? well sometimes it might be possible to develop a complex query which drilled right down to the exact data but this might take time to perfect when you could have coded it much quicker.
What's more I have found that over-complex queries are not very future proof, by that I mean a small change in the specification and they have to be rewritten. Further more they may not be very easy for other programmers to understand/maintain.
So do the best query you can and then manipulate the data in your code.
Truism: SQL can never be so flexible as a scripting/programming language such as PHP/Perl
Labels: mysql, php, query optimisation, what to put in the code

0 Comments:
Post a Comment
<< Home