<?php

header('Content-Type: application/json');


$servername = "localhost";
$username = "u950110925_triggers";
$password = "[o2VJeI2";
$dbname = "u950110925_triggers";

$response = ['success' => false, 'data' => [], 'error' => ''];

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

// Check connection
if ($conn->connect_error) {
  $response['error'] = "Connection failed: " . $conn->connect_error;
  echo json_encode($response);
  exit();
}

$sql = "SELECT * FROM high_score ORDER BY score DESC LIMIT 10";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    $response['data'][] = $row;
  }
  $response['success'] = true;
} else {
  $response['error'] = "0 results";
}
echo json_encode($response);
$conn->close();
?>
