Re: assign mysql query to a variable first or not

From: Date: Wed, 07 Apr 2004 11:15:05 +0000
Subject: Re: assign mysql query to a variable first or not
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-182606@lists.php.net to get a copy of this message
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. [...]

« previous php.general (#182606) next »