使用类似的内部pg_prepare通配符(Using LIKE wildcards inside p

2019-06-24 12:13发布

我一直在尝试使用像一份声明中,但PHP不会因使用通配符%执行,因为语法错误的语句。

下面是代码

$query = pg_prepare($conn, "MyStatement", 
    'SELECT "Query" from "MyTable" 
     WHERE "Query" LIKE $1% 
     ORDER BY "MyColumn" DESC;');

$result = pg_execute($conn, "MyStatement", array($my_param));

问题是,PHP显示我在第二行声称语法错误警告。

Answer 1:

我已经使用PDO适配器同样的问题,结合参数。 解决的办法是与可变通过“%”:

$query = pg_prepare($conn, "MyStatement", 
'SELECT "Query" from "MyTable" 
 WHERE "Query" LIKE $1 
 ORDER BY "MyColumn" DESC;');

$result = pg_execute($conn, "MyStatement", array($my_param."%"));

如果你需要

...LIKE '%param%' ...

然后你的查询是:

$result = pg_execute($conn, "MyStatement", array("%".$my_param."%"));


文章来源: Using LIKE wildcards inside pg_prepare