-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetch.php
More file actions
33 lines (26 loc) · 780 Bytes
/
fetch.php
File metadata and controls
33 lines (26 loc) · 780 Bytes
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
<?php
$servername = "localhost";
$username = "root"; // Change if needed
$password = ""; // Change if needed
$dbname = "campus_safety_db"; // Updated database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch incidents
$sql = "SELECT id, latitude, longitude, description, reported_at FROM incidents ORDER BY reported_at DESC";
$result = $conn->query($sql);
$incidents = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$incidents[] = $row;
}
}
// Return JSON response
header('Content-Type: application/json');
echo json_encode($incidents);
// Close connection
$conn->close();
?>