RE: [PHP] how do you write queries in php codes? (was Re: [PHP] W hy doesn't this simple query work?)
| From: | Lawrence dot Sheed at dfait-maeci dot gc dot ca | Date: | Thu, 26 Jul 2001 02:38:55 +0000 |
| Subject: | RE: [PHP] how do you write queries in php codes? (was Re: [PHP] W hy doesn't this simple query work?) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-59669@lists.php.net to get a copy of this message | ||
Its however you prefer it (or whatever is easier to type usually).
sprintf is usable, depends on if you have a c or perl background, and its
second nature.
For me, I use editplus on windows which gives color coding
(www.editplus.com), if I do
$query = "select abc,def,ghi from table1,table2". $another_table ." where
abc='". $a ."'";
I can immediately see the $another_table, and $a are variables.
Use a color coded editor - it makes life a lot easier.
Lawrence.
-----Original Message-----
From: Moriyoshi Koizumi [mailto:readjust@deneb.freemail.ne.jp]
Sent: July 26, 2001 10:28 AM
To: php-general@lists.php.net
Subject: [PHP] how do you write queries in php codes? (was Re: [PHP] Why
doesn't this simple query work?)
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\' :)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net