I always see MySQL queries structured like this, even with the simplest of queries:
$query = "SELECT * FROM table_name WHERE id = '1'";
$result = mysql_query($query);
Is there any value, time or otherwise in doing the above over a simple one line query such as?
$result = mysql_query("SELECT * FROM table_name WHERE id = '1'";
I’ve always used the former, as when I started using PHP I thought it best to simply copy everyone else, however now that I’m working on a fairly large (relative to my other work) application, I could cut out a significant amount of arbitrary coding if there’s really no difference.
Generally, I like separating them because I can easily do
print $query;when I’m trying to figure out why my query won’t work. It’s mostly a matter of personal preference.