Page 1 of 1

Passing strings that contain variables to be parsed later

Posted: Tue Dec 07, 2004 9:36 am
by VetteVert
I have a configuration file with the equivalent of the following:

sql_statement = "select * from $table a where a.x = '$x'"

I then read the sql_statement line from the configuration file in another php file where I would like $table and $x to be parsed. If I leave it like above, it tries to parse it immediately, not later when I need it. Does anyone have any idea on how the sql_statement line could be written so that it would be parsed in the file that reads it?

Thanks!!

Posted: Tue Dec 07, 2004 9:45 am
by timvw
how do you read it? [php_man]file_get_contents[/php_man]
how do you to [php_man]eval[/php_man] the code in the text?

Posted: Tue Dec 07, 2004 9:54 am
by VetteVert
The sql_statement string is in config.php, and is included in another php file.

I get to it by going through the array it is in and assign it to $sql:

$x = 'BOB';
$sql = $array["here"]["there"]["sql_statement"];

at this point the variable has already been processed and is blank ('') and not BOB.

Posted: Fri Dec 10, 2004 8:59 am
by VetteVert
anybody?

Posted: Tue Dec 14, 2004 2:35 pm
by VetteVert
guess not :?

Posted: Tue Dec 14, 2004 2:43 pm
by rehfeld
timvw gave you 2 solutions.

Posted: Tue Dec 14, 2004 2:47 pm
by VetteVert
I caught the first one that didn't apply to me, but somehow completely missed the second...which is exactly what I was asking for. I apologize for the oversight.

Thanks!

VV