[prev in list] [next in list] [prev in thread] [next in thread]
List: php-db
Subject: [PHP-DB] Benefits of assigning query to variable
From: "Adam Royle" <digitalbalance () mac ! com>
Date: 2002-07-31 22:38:47
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic