-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetsystem.php
More file actions
32 lines (27 loc) · 1000 Bytes
/
getsystem.php
File metadata and controls
32 lines (27 loc) · 1000 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
<?php
// Database connection details
$servername = "localhost:3306"; // usually localhost
$username = "root"; // your database username
$password = "monish777"; // your database password (default is empty for XAMPP/WAMP)
$dbname = "COSMIC"; // the name of your database
// Create a connection to the MySQL database
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch data from the StarSystems table
$sql = "SELECT * FROM StarSystems"; // your table name
$result = $conn->query($sql);
// Check if any data was fetched
if ($result->num_rows > 0) {
$starSystems = [];
while ($row = $result->fetch_assoc()) {
$starSystems[] = $row;
}
echo json_encode($starSystems); // Return star system data as JSON
} else {
echo json_encode([]); // Empty array if no results
}
$conn->close();
?>