how do you write queries in php codes? (was Re: [PHP] Why doesn't this simple query work?)
| From: | Moriyoshi Koizumi | Date: | Thu, 26 Jul 2001 02:28:20 +0000 |
| Subject: | how do you write queries in php codes? (was Re: [PHP] Why doesn't this simple query work?) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-59667@lists.php.net to get a copy of this message | ||
yes,
both of yours make the same result too, and are clean :-)
and i wonder what the best way is, to put queries into php code...
there's a more complicated sample,
$a=addslashes($a);
$b=addslashes($b);
$c=addslashes($c);
if( $another_table ) { $another_table=','.$another_table; }
$query = "select abc,def,ghi
from table1,table2 $another_table
where abc='$a' and def='$b' and ghi='$c' ";
and i prefer because i often confuse php variables with columns
if( $another_table ) { $another_table=','.$another_table; }
$query = sprintf(
'select abc,def,ghi
from table1,table2 %s
where abc="%s" and def="%s" and ghi="%s"',
$another_table,
addslashes($a), addslashes($b), addslashes($c)
);
but i think the latter loses some good php features...
then, does anyone have good idea?
Lawrence.Sheed@dfait-maeci.gc.ca wrote:
> how about
>
> $location = addslashes($location);
> $query = "select shoodID from shoots where location = '$location'";
>
> or
>
> $query = "select shoodID from shoots where location = '".
> addslashes($location) ."'";
>
>
> Both are \'clean\' :)