<?php
// error_reporting(E_ALL);
//     ini_set('display_errors', 1);
    require('connect.php');

    $conn = new mysqli($host, $user, $pass, $database);

    $sql = "SELECT * FROM `last_data`";

    $result = mysqli_query($conn, $sql);

    $data = array();

    if (mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        
            $data=array('datetime'=>$row['datetime'],
            'device'=>$row['device']);

        $response = array(
            'success' => 'yes',
            'data' => $data // Dodanie tablicy danych do odpowiedzi
        );
    } else {
        $response = array(
            'success' => 'no',
            'message' => 'Brak danych'
        );
    }

    $conn->close();

    header('Content-Type: application/json');
    echo json_encode($response);
?>
