<?php
$host = "localhost";
$user = "bant5829_admgame";
$pass = "Dodol@25?";
$db   = "bant5829_game";

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
  http_response_code(500);
  echo "Koneksi gagal";
  exit;
}

$result = $conn->query("SELECT * FROM posisi_pc");
$data = [];
while ($row = $result->fetch_assoc()) {
  $data[$row['id']] = [
    'x' => (int)$row['x'],
    'y' => (int)$row['y'],
    'arah' => $row['arah'],
    'aksi' => $row['aksi'],
    'idx' => $row['id']
  ];
}
echo json_encode([
  'pc1' => $data['pc1'] ?? ['x'=>0,'y'=>0,'arah'=>'kanan','aksi'=>'','idx'=>'pc1'],
  'pc2' => $data['pc2'] ?? ['x'=>0,'y'=>0,'arah'=>'kanan','aksi'=>'','idx'=>'pc2'],
  'pc3' => $data['pc3'] ?? ['x'=>0,'y'=>0,'arah'=>'kanan','aksi'=>'','idx'=>'pc3'],
]);
$conn->close();
?>
