我一直在尝试使用像一份声明中,但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显示我在第二行声称语法错误警告。
我已经使用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."%"));