'FeatureCollection', 'features' => array() ); try { $dbcon = new PDO("pgsql:host=".$dbconfig['_pgsql_db_host_'].";port=".$dbconfig['_pgsql_db_port_'].";dbname=".$dbconfig['_pgsql_db_name_'].";user=".$dbconfig['_pgsql_db_user_'].";password=".$dbconfig['_pgsql_db_pass_'].""); $dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbcon->prepare("SELECT id, notes, ST_AsGeoJSON(geom, 4326, 1) AS geojson FROM interventi_polygon WHERE idpratica = ".$_SESSION['IDPRATICA'].""); if($stmt->execute()){ $id_count = 0; while($rowset = $stmt->fetch(PDO::FETCH_ASSOC)){ $properties = $rowset; unset($properties['geojson']); unset($properties['geom']); $feature = array( 'type' => 'Feature', 'id' => $id_count, 'properties' => $properties, 'geometry' => json_decode($rowset['geojson'], true) ); array_push($geojson['features'], $feature); $id_count++; } header('Content-Type: application/json'); echo json_encode($geojson, JSON_NUMERIC_CHECK); $dbcon = null; exit; } else { header('Content-Type: application/json'); echo json_encode($geojson, JSON_NUMERIC_CHECK); $dbcon = null; exit; } } catch (PDOException $e) { header('Content-Type: application/json'); echo json_encode($geojson, JSON_NUMERIC_CHECK); $dbcon = null; exit; } ?>