gpt4 book ai didi

php eval 和 pg_execute 不工作!参数

转载 作者:行者123 更新时间:2023-11-29 13:49:57 26 4
gpt4 key购买 nike

我错过了什么?我正在构建一个动态查询并为 postgres 准备查询。它应该可以工作,但 eval 语句并没有发挥它的魔力。我错过了什么?

除了eval之外,还有其他方法可以传递带有多个变量的字符串吗?谢谢。

简要说明。

$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
}

哦,我也做过

$result = eval('return $runthis');

没有错误产生。准备被记录在 postgres 日志文件中,但 pg_execute 从未发生。

我是否漏掉了一些非常明显的东西?

谢谢

JT

最佳答案

改变了

$pgarray[]   = "\$city";
$pgarray[] = "\$country";

$pgarray[]   = $city;
$pgarray[] = $country;

$runthis = "pg_execute(\$dbconnect, 'q1', array($pgarray) )";

$result = pg_execute($dbconnect, 'q1', $pgarray );

它解决了问题,或者我应该说我的错误代码。

关于php eval 和 pg_execute 不工作!参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42776922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com