-
Notifications
You must be signed in to change notification settings - Fork 1
/
getRows.php
34 lines (28 loc) · 904 Bytes
/
getRows.php
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
<?php
// Path to your SQLite database
$dbPath = 'locations.db';
// Create a connection to the SQLite database
try {
$pdo = new PDO("sqlite:$dbPath");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo json_encode(['error' => 'Connection failed: ' . $e->getMessage()]);
exit();
}
// Get the POST data
$postData = file_get_contents("php://input");
$request = json_decode($postData, true);
if ($request['action'] === 'getAllRows') {
try {
// Prepare SQL query to get all rows from a table (replace 'your_table_name' with the actual table name)
$stmt = $pdo->query("SELECT * FROM Location");
// Fetch all rows
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Send rows as JSON
echo json_encode($rows);
} catch (PDOException $e) {
echo json_encode(['error' => 'Query failed: ' . $e->getMessage()]);
}
}
$pdo = null;
?>