<?php
// Database credentials
$servername = "mysql.liacs.leidenuniv.nl";
$username = "sXXXXXX";
$password = "XXXXXX"; 
$dbname = "sXXXXXX";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Execute query
$sql = "SELECT * FROM donuts";
$result = $conn->query($sql);

$array = array();

// Fetch results
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        array_push($array, 	array('name' => $row['Name'], 'donuts' => $row['Donuts_eaten']));
    }
} else {
    echo "0 results";
}

// Encode to JSON to read with Javascript.
echo json_encode($array, JSON_PRETTY_PRINT);

// Close connection
$conn->close();
?>