Re: Re: Vars inside an sql query [Regular expression question]
| From: | Hatem Ben | Date: | Thu, 12 Jun 2003 11:07:57 +0000 |
| Subject: | Re: Re: Vars inside an sql query [Regular expression question] | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-151231@lists.php.net to get a copy of this message | ||
Sorry this is more correct :
------ starting query.php
select * FROM
table where id='$value' order by name
------ ending query.php
"Hatem Ben" <reflex_news@yahoo.fr> a écrit dans le message de news:
20030612120432.85609.qmail@pb1.pair.com...
> Oh, ok this is how i want to do it exactly :
> ------------ query.php
> <?php
> $query = "select * FROM table where id='$value'
> order by name";
> ?>
>
> ------------ parse.php
> <?php
> $fcontents = join('' , file('query.php'));
> preg_match_all("/^('\$(.*)')/si", $fcontents,$matches);
> print_r($matches)
> ?>
>
> Thanks
>
> "Chris Hayes" <chayes@antenna.nl> a écrit dans le message de news:
> 5.2.0.9.0.20030612134632.027a6da0@pop4.antenna.nl...
> > At 13:54 12-6-03, you wrote:
> > >>I got a headache doing this, i need to get vars inside an sql query.
For
> > >>example :
> > >>
> > >>$query = "select * FROM table where
> > >>id='$value' order by name";
> > >>preg_match_all("/^('\$(.*)')/si", $query,$matches);
> >
> >
> > >That doesn't work as the new string already is like "select * FROM
> table
> > >where id='2' order by name" assuming $value was 2...
> >
> > True, so try using
> >
> > $query = "select * FROM table where
> > id='__VALUE__' order by name";
> >
> > if you insist on doing it this way.
> >
> > If you decide to keep trying with the $value, you need to know that
> > variables inside "double quotes" are entered on the spot, while not so
> with
> > 'single quotes'.
> >
> >
> > Also it is nice to know that the $ has a special position in
> preg_matching,
> > i kept this mail from a post from december in this list:
> >
> > > such as $, you must escape it twice. For example:
> > >
> > > $matchme = "\$example";
> > > if (preg_match("/\$example/", $matchme)) {
> > >
> > > will not be matched because PHP interprets the \$ and passes it as $.
> > > Instead, you must do this:
> > >
> > > if (preg_match("/\\\$example/", $matchme)) {
> >
>
>