<?php

declare(strict_types=1);

// Database connection settings
$dbHost = 'localhost';
$dbUser = 'truehostuptime';
$dbPassword = 'truehostuptime1';
$dbName = 'mysql';

// Connect using MySQLi
$conn = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);

if ($conn->connect_error) {
    http_response_code(500);
    die(json_encode(['error' => 'DB is down: Connection failed.', 'details' => $conn->connect_error]));
}

// Run test query
$result = $conn->query('SELECT 1');
if (!$result) {
    http_response_code(500);
    die(json_encode(['error' => 'DB is down: Query failed.', 'details' => $conn->error]));
}

echo json_encode(['message' => 'DB is online']);
$conn->close();

