Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
661 B
2
Indexable
Never
<?php
header('Content-Type: application/json');
$servername = "localhost";
$username = "root";
$password = "";
$database_name = "versiune0";

$conn = new mysqli($servername, $username, $password, $database_name);
if ($conn->connect_error) {
    echo json_encode(['error' => "Connection failed: " . $conn->connect_error]);
    exit;
}

// Select all data from the table
$sql = "SELECT id, temp, humi, press, CO, dist, butt, posi FROM tabel";
$result = $conn->query($sql);

$data = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}
echo json_encode($data);

$conn->close();
?>
Leave a Comment