0

I want to print string value inside query. I defined variable in array. On the below main query that is working when I execute query I get result.

$query = "SELECT count, mahkoy_kod , mahkoy_adi, ilce_id, st_x(st_transform(st_centroid(t2.geom),4326)) as lng,st_y(st_transform(st_centroid(t2.geom),4326)) as lat from 
(SELECT count(*),t1.knt_f_mahkoy_id FROM a.s_all t1                                             
where st_intersects(t1.geom,st_transform(ST_GeomFromText( format('POLYGON((%s %s, %s %s, %s %s, %s %s, 
%s %s))', 29.743849487304715, 41.24992343698962, 28.481108398437527, 41.24992343698962, 
28.481108398437527, 40.749326052646055, 29.743849487304715, 40.749326052646055, 
29.743849487304715, 41.24992343698962 ), 4326),500000)) 
group by knt_f_mahkoy_id ) t1
join analiz.k_spt_dis_mah_koy t2 on t1.knt_f_mahkoy_id = t2.mahkoy_kod 
where  count > 100";

When I use php pdo I get error is

Could not determine data type of parameter $1 Blockquote

It is php code. Here database class used to run query. When I print data with var_dump I get error. How can I solve this problem?

$query = "SELECT count, mahkoy_kod , mahkoy_adi, ilce_id, st_x(st_transform(st_centroid(t2.geom),4326)) as lng,st_y(st_transform(st_centroid(t2.geom),4326)) as lat from 
(
  SELECT count(*),t1.knt_f_mahkoy_id FROM a.s_all t1                                             
  where st_intersects(t1.geom,st_transform(ST_GeomFromText( format('POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))', 
 :long_high, :lat_high, :long_low, :lat_high, :long_low, :lat_low, :long_high, :lat_low, :long_high, :lat_high ), 4326),500000)) 
  group by knt_f_mahkoy_id 
) t1
  join analiz.k_spt_dis_mah_koy t2 on t1.knt_f_mahkoy_id = t2.mahkoy_kod  where  count > 100";

$data = Database::query($query, array("long_high"=>$long_high, "lat_high"=>$lat_high, "long_low"=>$long_low, "lat_low"=>$lat_low));

1 Answer 1

1

I am not much into postgres but suppose you can do it another way

$polygon = sprintf('POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))', 
$long_high, $lat_high, $long_low, $lat_high, $long_low, $lat_low, $long_high, $lat_low, $long_high, $lat_high);

$query = "SELECT count, mahkoy_kod , mahkoy_adi, ilce_id, st_x(st_transform(st_centroid(t2.geom),4326)) as lng,st_y(st_transform(st_centroid(t2.geom),4326)) as lat from 
(
  SELECT count(*),t1.knt_f_mahkoy_id FROM a.s_all t1                                             
  where st_intersects(t1.geom,st_transform(ST_GeomFromText( ?, 4326),500000)) 
  group by knt_f_mahkoy_id 
) t1
  join analiz.k_spt_dis_mah_koy t2 on t1.knt_f_mahkoy_id = t2.mahkoy_kod  where  count > 100";

$data = Database::query($query, array($polygon));

the idea here is to provide a POLYGON function as a complete string literal. It is both safe and compatible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.