I'm working on a project where I need to store a CGI query in a
database field. The query contains variables which will be substitued
at runtime (e.g., today's date, key to select upon, etc), and may be
pointed to different URLs depending upon the table key.
The variable substitution works fine when hardcoding into the script,
e.g.:
$var1='data1';
$var2='data2';
$a="http://www.webserver.c om/query.cgi?a=$va r1&b=$var2";
$fd=fopen($a,"r ");
...
However, the substitution fails when the query is pulled from a database
record, e.g.
//Only one record returned for testing purposes.
//
//location field (varchar) is:
//"http://www.webserver.c om/query.cgi?a=$va r1&b=$var2"
$var1='data1';
$var2='data2';
$dbconn=yadda yada;
$dbquery=pg_que ry($dbconn,"sel ect key,location from schema.table");
$row=pg_fetch_a ssoc($dbquery);
$fd=fopen($row['location'],"r");
...
In this case, the variable substitution doesn't occur in the query (i.e.,
$var1 remains the string $var1, instead of changing into the value of say,
'03-23-2004'). I've tried different variations, and treating as a
variable variable (with $$row['url'] and ${$row['url']}. No joy.
Any ideas would be appreciated. Thanks.
-------------------------------------------------
Only in America will someone |
order a Big Mac, large fries, | bofh@visi.com
and a *Diet* Coke... |
database field. The query contains variables which will be substitued
at runtime (e.g., today's date, key to select upon, etc), and may be
pointed to different URLs depending upon the table key.
The variable substitution works fine when hardcoding into the script,
e.g.:
$var1='data1';
$var2='data2';
$a="http://www.webserver.c om/query.cgi?a=$va r1&b=$var2";
$fd=fopen($a,"r ");
...
However, the substitution fails when the query is pulled from a database
record, e.g.
//Only one record returned for testing purposes.
//
//location field (varchar) is:
//"http://www.webserver.c om/query.cgi?a=$va r1&b=$var2"
$var1='data1';
$var2='data2';
$dbconn=yadda yada;
$dbquery=pg_que ry($dbconn,"sel ect key,location from schema.table");
$row=pg_fetch_a ssoc($dbquery);
$fd=fopen($row['location'],"r");
...
In this case, the variable substitution doesn't occur in the query (i.e.,
$var1 remains the string $var1, instead of changing into the value of say,
'03-23-2004'). I've tried different variations, and treating as a
variable variable (with $$row['url'] and ${$row['url']}. No joy.
Any ideas would be appreciated. Thanks.
-------------------------------------------------
Only in America will someone |
order a Big Mac, large fries, | bofh@visi.com
and a *Diet* Coke... |
Comment