pg_prepare($con, "prep", "select * from test where tid in ($1)");
然后执行它:
$strpar = "3,4,6,8,10";
pg_execute($con, "prep", array($strpars));
问题是我无法传递一系列构建的值,因为prepare需要固定数量的参数.有没有办法让参数动态化?
解决方法:
使用数组表示一系列值:
pg_prepare($con, "prep", "select * from test where tid=ANY($1::int[])");
$strpar = "{3,4,6,8,10}";
pg_execute($con, "prep", array($strpars));
如果规划器能够自己推断类型,则查询中对int []的强制转换甚至可能是多余的.