Re: Style questions: variable in echo, preparing sql queries
| From: | Richard Lynch | Date: | Fri, 24 Nov 2000 20:01:07 +0000 |
| Subject: | Re: Style questions: variable in echo, preparing sql queries | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-27027@lists.php.net to get a copy of this message | ||
> 1) echo "PartID is $PartID";
> seems to work fine. Is there a reason that I see others use:
> echo "PartID is " . $PartID;
If $PartID is not a simple variable, but an array or object, the embedded
used to not work. Now, it works but not for 2-D (and higher) arrays, and I
dunno about objects...
For echo, you can also use , instead of . since echo takes unlimited args.
> 2) When querying a db, I see users who do something like:
> $sql = "select foo from bar";
> $results = mysql_query("$sql")
> Is there a reason not to just put the SQL code directly in the function:
> $results=mysql_query("select foo from bar") ?
Yes. When (not if, when) I screw up the SQL, I want to be able to easily
insert:
echo $sql, "<BR>\n";
before the mysql_query() line.
And then comment it out after I fix my broken SQL.