One of the greatest benefits is the fact, that you can easily display your
actual query without copying it, passing it to a variable and then display
it's content:

$result = mysql_query( .... );

would first become:

$var = .... ;
$result = mysql_query( .... );
echo $var ;

now if the query fails, you have to rewrite the Query, copy it to the variable 
again etc. pp

When doing

$var = ..... ;
$result = mysql_query( $var );
echo $var ;

you just have to rewrite one query instead of two. This way of working only
helps you to debug a little faster.

[...]
> AB> is it better to give the mysql query string to a variable
> AB> instead of directly doing it with mysql_query?
>
> AB> i.e.
> AB> $query="select * from table";//is this a better way?
> AB> $query=mysql_query("select * from table");//or is this way
> AB> //better?
> AB> mysql_query("select * from table");//not a good idea i dont think...
>
> Most people here probably use some kind of database abstraction layer
> already (ADOdb, a Pear lib, or a home-grown one, etc). While you are
> not doing this at the moment, if you hold the query in a string before
> passing to MySQL it means you could implement a database handler in
> the future with minimal code changes and not have to re-do every
> single query.
>
> There are other benefits, but that one strikes me as the most
> important at the moment.
[...]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to