<?php
/**
 * Test Connection API
 * Check database status: https://webapp69.cm.in.th/u69319090023/Shop23/api/test_connection.php
 */

require_once __DIR__ . '/db.php';

try {
    $version = $pdo->query('SELECT VERSION()')->fetchColumn();
    $tables = $pdo->query('SHOW TABLES')->fetchAll(PDO::FETCH_COLUMN);

    sendResponse(true, [
        'status'         => 'connected',
        'database_name'  => $DB_NAME,
        'mysql_version'  => $version,
        'tables'         => $tables,
        'server_time'    => date('Y-m-d H:i:s')
    ], 'เชื่อมต่อกับฐานข้อมูล MySQL บนเซิร์ฟเวอร์สำเร็จสมบูรณ์!');
} catch (Exception $e) {
    sendResponse(false, null, 'เกิดข้อผิดพลาด: ' . $e->getMessage(), 500);
}
