pg_query_params不允许使用带引号的占位符

时间:2019-08-02 14:29:45

标签: php postgresql

我正在处理一个postgreSQL查询,该查询正在搜索几何中包含的列,并且如果通过pgAdmin运行它可以很好地工作,但是我无法使其通过PHP与pg_query_params一起工作

这是有效的查询

select a.full_address from streets a, gisgeometry b where b."Name" ILIKE ANY ('{%Barnet%}') AND ST_CONTAINS(b.sp_geometry,a.wkb_geometry) and a.full_address ilike '%high street%' group by a.full_address ORDER BY a.full_address LIMIT 100;

如果通过PHP询问,我可以使其与pg_query

一起使用
$result = pg_query($connect,'select a.full_address from streets a, gisgeometry b where b."Name" ILIKE ANY ('.$bbox.') AND ST_CONTAINS(b.sp_geometry,a.wkb_geometry) and a.full_address ilike '.$pattern.' group by a.full_address ORDER BY a.full_address LIMIT 100;');

不与pg_query_params

$result = pg_query_params($connect,'select a.full_address from streets a, gisgeometry b where b."Name" ILIKE ANY ($1) AND ST_CONTAINS(b.sp_geometry,a.wkb_geometry) and a.full_address ilike $2 group by a.full_address ORDER BY a.full_address  LIMIT 100;', array($bbox, $pattern));

我当然会进行环境卫生以及PHP中的所有操作,并且使用pg_query可以使其工作(我的意思是在变量周围加上单引号)

  $pattern = fixtags($_POST['findthis']);
  $pattern = str_replace(" ", "%", $pattern);
  ## add single quotes and % around the pattern
  $pattern = "'%".$pattern."%'";

  $bbox = fixtags($_POST['ext']);
  $bbox = explode(",", $bbox);

  foreach ($bbox as &$value) {
    $value = "%$value%";
  }

  $bbox = implode(",", $bbox);
  ## add single quotes and {} around the pattern
  $bbox = "'{". $bbox ."}'";

使用$pattern = "%".$pattern."%";$bbox = "{". $bbox ."}";而不使用单引号或使用上述引号引起的错误是:

Got error 'PHP message: PHP Warning:  pg_query_params(): Query failed: ERROR:  array value must start with "{" or dimension information in ...php on line 367\nPHP message: ..

0 个答案:

没有答案