<?php
header('Content-Type: application/json');
$host='localhost'; $user='root'; $pass=''; $name='wachat';
try {
    $p = new PDO("mysql:host=$host;charset=utf8mb4",$user,$pass,[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
    $dbs = $p->query("SHOW DATABASES LIKE 'wachat'")->fetchAll(PDO::FETCH_COLUMN);
    if (!$dbs) { echo json_encode(['error'=>'Database "wachat" does not exist. Run database.sql in phpMyAdmin.']); exit; }
    $p->exec("USE wachat");
    $tables = $p->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);
    echo json_encode(['ok'=>true,'tables'=>$tables]);
} catch(PDOException $e) {
    echo json_encode(['error'=>$e->getMessage()]);
}
