<?php
declare(strict_types=1);
require_once __DIR__ . '/db.php';

header('Content-Type: text/plain; charset=utf-8');

try {
  $pdo = db();
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $db = $pdo->query("SELECT DATABASE()")->fetchColumn();
  echo "Connected DB: " . ($db ?: '(null)') . "\n\n";

  echo "Tables:\n";
  $rows = $pdo->query("SHOW TABLES")->fetchAll(PDO::FETCH_NUM);
  foreach ($rows as $r) {
    echo "- " . $r[0] . "\n";
  }

  echo "\nTry find likely cases tables:\n";
  foreach ($rows as $r) {
    $t = strtolower((string)$r[0]);
    if (strpos($t, 'case') !== false || strpos($t, 'قض') !== false) {
      echo "* " . $r[0] . "\n";
    }
  }

} catch (Throwable $e) {
  echo "ERROR: " . $e->getMessage();
}