What am I missing? I am building a dynamic query and preparing the query for postgres. It should work but the eval statement does not do it's magic. What am I missing?
Is there another way to pass a string with multiple variables besides the eval? Thanks.
The brief explanation.
$condition = array();
$values = array();
$pgarray = array();
$country = 254;
$city = "Seattle";
$condition[] = " AND city = $";
$values[] = $city;
$pgarray[] = "\$city";
$condition[] = " AND country = $";
$values[] = $country;
$pgarray[] = "\$country";
$as = sizeof($condition);
for ( $x=0; $x<$as; $x++ ) {
$index = $x + 1; //We need to start at one not 0
$qclause = $qclause . $condition[$x] . $index . " ";
}
// This is what qclause equates to.
// AND city = $1 AND country = $2
$pgarray = implode(", ", $pgarray);
// This is what pgarray equated to.
// $city, $country
$query = "Select companyid, city, name from company where 1 = 1 $qclause";
$result = pg_prepare($dbconnect, 'q1', $query);
$runthis = "pg_execute(\$dbconnect, 'q1', array($pgarray) )";
// This is what $runthis equated to.
// pg_execute($dbconnect, 'q1', array($city, $country) )
$result = eval($runthis);
While ..... {
bla bla bla
}
Oh, I have also done
$result = eval('return $runthis');
No errors are generated. The prepare gets logged in postgres log file but the pg_execute never happens.
Am I missing something really obvious ?
Thanks
JT
Changed
$pgarray[] = "\$city";
$pgarray[] = "\$country";
TO
$pgarray[] = $city;
$pgarray[] = $country;
And
$runthis = "pg_execute(\$dbconnect, 'q1', array($pgarray) )";
TO
$result = pg_execute($dbconnect, 'q1', $pgarray );
And it solved the problem or should I say my buggy code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.