Defered interpolation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

I'm wondering if this is possible with PHP:

$query = "SELECT * FROM table WHERE afield='$something'";

has quite a different meaning from

$query = 'SELECT * FROM table WHERE afield='$something'';

I'm trying to work out if it is possible to use the latter as a primitive
sort of data-binding (I know its not going to prevent injection). I would
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?



Re: Defered interpolation

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

Quoted text here. Click to load it
Quoted text here. Click to load it

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

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

position or variables etc.):<
-- =

Rik Wasmus

Re: Defered interpolation

Kimmo Laine wrote:
Quoted text here. Click to load it

Unless next_page.php generates PHP, the script with this include will
only get HTML.

Quoted text here. Click to load it


    if (isset($_GET['foo'])) {
      echo '<?php echo $_GET[\'foo\']; ?>';
    } else {
      echo '<?php echo \'Not available\'; ?>';

File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot

Site Timeline