Benefits of assigning query to variable

From: Date: Wed, 31 Jul 2002 22:38:47 +0000
Subject: Benefits of assigning query to variable
Groups: php.db 
Request: Send a blank email to php-db+get-20931@lists.php.net to get a copy of this message
Yes, I see a few benefits. 1. It makes the code easier to read. 2. It makes the code easier to debug. Imagine the following: $sql = "SELECT * FROM tblName"; $result = mysql_query($sql); Now if you want to print the sql and not do the select, you would simply add a line $sql = "SELECT * FROM tblName"; test($sql); $result = mysql_query($sql); where the function "test" is: function test($var){ echo $var; exit(); } The benefits are more evident when you have bigger sql queries, such as: $sql = "INSERT INTO tblName SET field1 = 'something1', field2 = 'something2', field3 = 'something3', field4 = 'something4'"; $result = mysql_query($sql); Hope that answers your question. Adam

« previous php.db (#20931) next »