-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_data.php
More file actions
35 lines (33 loc) · 1.04 KB
/
fetch_data.php
File metadata and controls
35 lines (33 loc) · 1.04 KB
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
<?php
$dbname = 'postgres';
$user = 'postgres';
$password = 'mas786mas';
$host = 'localhost';
$port = '5432';
// Connect to the PostGIS database
$conn = pg_connect("dbname=$dbname user=$user password=$password host=$host port=$port");
// Check if the connection was successful
if (!$conn) {
echo "An error occurred.\n";
exit;
} else {
// Fetch the location points from the database
$result = pg_query($conn, "SELECT ST_X(geom) AS lng, ST_Y(geom) AS lat FROM location_data.points");
// Check if the query was successful
if (!$result) {
echo "Data Fetch error\n";
exit;
} else {
// Create an array to store the location points
$locationPoints = array();
// Loop through the rows returned by the query
while ($row = pg_fetch_assoc($result)) {
// Add the location point to the array
$locationPoints[] = $row;
}
// Return the array as JSON
echo json_encode($locationPoints);
}
// Close the database connection
}
pg_close($conn);