1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| <?php
include ("dbconfig.php");
if(!isset($_SESSION)) { session_start(); };
error_reporting(E_ALL);
ini_set("display_errors", 1);
header("Access-Control-Allow-Origin: *");
$objectfile = $_GET['current_filepost'];
$geojson = array(
'type' => 'FeatureCollection',
'features' => array()
);
try {
$dbcon = new PDO("pgsql:host=".$dbconfig['_pgsql_db_host_'].";port=".$dbconfig['_pgsql_db_port_'].";dbname=mfy_26;user=".$dbconfig['_pgsql_db_user_'].";password=".$dbconfig['_pgsql_db_pass_']."");
$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbcon->prepare("SELECT gid, name, cat, comment, description, public.ST_AsGeoJSON(public.ST_Transform((geom),4326),6) AS geojson FROM :current_file");
//$stmt->bindValue(":current_file", $objectfile, PDO::PARAM_STR); //tentative1
//$stmt->bindParam("s", $objectfile); //tentative2 en remplacant :current_file par ?
if($stmt->execute(array( //tentative3
':current_file' => $objectfile))){
$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;
}
?> |
Partager