You are here: Re: Defered interpolation « PHP Programming Language « IT news, forums, messages
Re: Defered interpolation

Posted by Rik on 02/17/07 17:03

On Sat, 17 Feb 2007 14:36:28 +0100, Colin McKinnon =

<colin.thisisnotmysurname@ntlworld.deletemeunlessURaBot.com> wrote:

> Hi all,
>
> I'm wondering if this is possible with PHP:
>
> $query =3D "SELECT * FROM table WHERE afield=3D'$something'";
>
> has quite a different meaning from
>
> $query =3D 'SELECT * FROM table WHERE afield=3D\'$something\'';
>
> I'm trying to work out if it is possible to use the latter as a primit=
ive
> sort of data-binding (I know its not going to prevent injection). I wo=
uld
> create $query before the value of $something is finalised, then apply =
the
> interpolation operation on $query to get it to substitute the variable=
at
> that point.
>
> Is there an easy way to do this with PHP?

$querystring =3D 'SELECT * FROM `table` WHERE `afield` =3D \'%s\'';
$explicit_query =3D sprintf($querystring,'something');

Look at he manual for more options (display as integere, swap around =

position or variables etc.):<http://www.php.net/sprintf>
-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация