|
Posted by Schraalhans Keukenmeester on 09/28/05 02:26
s1037989@gmail.com wrote:
> The question in short:
> Do you allow MySQL to perform all functions that it can, returning
> immediately the exact desired data with almost NO more processing
> necessary by PHP *or* do you keep your SQL statements rather generic,
> simplified, and minimal, and allow PHP to further process the received
> data to specifications?
>
> More elaborated:
>
> I'm writing a very simple php-based web application. All it does is
> post and or get data and displays it on the web.
>
> However, the difficulty is in the MySQL statements. The statements are
> (IMO) huge and quite specific (non-reuseable)! Additionally, many
> statements are near identical to others, but are so complex that I see
> no way to neatly introduce variables into the SQL statement (plus
> wanting to avoid SQL injection...)
>
> I am curious about others' coding techniques. In such an instance, do
> you nasty-up your PHP code with many different, large SQL statements?
>
> Do you try to shove your SQL queries into a class with function
> accessibility, even tho there is little connection between one query
> and another (I only see this as making an overly-complex function in
> order to get to a few varieties of semi-similar SQL statements, still
> needing of course many of these functions for those that completely do
> not relate)?
>
> Do you just totally extract the SQL statements, storing them in a
> 'define', and referencing each statement as its own constant (in which
> case there will be MANY define'd SQL statements, one for every single
> type of query regardless of how similiar one statement may be to
> another, and therefore almost unmanageable constant names)?
>
> Or, do you possibly not make your MySQL statements so complex and let
> PHP do processing (allowing SQL statements to be very generic and
> therefore minimal in quantity)?
>
> For now, I think that last one is the big question. Which is better
> style -- which is preferred -- PHP data processing or MySQL data
> processing?
>
> If the thread carries on, perhaps I can elaborate more, but in short, I
> feel that anytime MySQL can process the data, further reducing
> processing by PHP, it should. My reason is that, IMO, it makes your
> PHP code more readable. You can read the PHP and look at the complex
> SQL statement as tho it were a completely seperate module. It doesn't
> matter HOW that module works, just that it gives the data you want.
> And if it gives the data you want, you don't have to clutter up your
> immediate coding space with further data processing. Just take your
> data and go on.
>
> I welcome any further dicussion relating to this and value anyone's
> opinion that posts.
>
> Thanks!
> Stefan
>
In short: I prefer simple MySQL queries and reusable PHP processing
blocks. That said, MySQL may be a better/faster/more elegant solution in
many applications. All depends on what you are doing. Hard to judge I think.
Maybe you can share some detail of the issues at hand ?
And of course: what do YOU feel comfortable with. Is it just a matter of
striving for a neat looking result or is there money at stake ?
Rgds
SH
[Back to original message]
|