PHP knows nothing about the SQL query sent to PostGIS. Therefore, it doesn't matter if you have nested queries or not.
But it is very important for PostGIS, in order to perform the query, to receive a valid query, like you did when you have used PgAdmin.
So, I think you need to revise your php $sql variable, like this:
$sql = "SELECT name, ST_AsKML(ST_Transform(geom,26918)) AS kmlgm FROM Buildings WHERE ST_DWithin(ST_Transform(geom, 26918), (SELECT ST_Transform(ST_GeomFromText('POINT(1116858.6062789 7086290.6680572)', 900913), 26918)), 1000)";
manpreet
Best Answer
2 years ago
I have a simple problem regarding a nested query. I would like to select all buildings in a given circular buffer and create a kml file of those selected objects. The following query does the job very well and returns the results when I run it in PgAdmin.
the "POINT(1116858.6062789 7086290.6680572)" is the center of the circle, and the value 1000 is the radius.
As you can see the query has another SELECT inside it (nested).
The following PHP code is able to generate kml file based on the results of query. I have already tested it with a simple SELECT query and it works">works fine. However, when I use the above-metioned query it does not work, and it does not give an error.
Does this mean that PHP does not support nested query?!
I'm a beginner, Can anybody please help me to find where the problem is and how it can be solved?
PHP code: