<?php
declare(strict_types=1);

ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting(E_ALL);

echo "DIR=" . __DIR__ . "<br>";

$candidates = [
  __DIR__ . '/db.php',
  __DIR__ . '/inc/db.php',
  __DIR__ . '/../db.php',
  __DIR__ . '/../../db.php',
];

echo "<pre>";
foreach ($candidates as $p) {
  echo (is_file($p) ? "[FOUND] " : "[MISS ] ") . $p . "\n";
}
echo "</pre>";

$found = null;
foreach ($candidates as $p) {
  if (is_file($p)) { $found = $p; break; }
}

if (!$found) {
  die("No db.php found in any candidate path.");
}

require_once $found;

if (!function_exists('db')) {
  die("db.php loaded but function db() NOT FOUND. Fix db.php to include function db():PDO");
}

$pdo = db();
if (!$pdo instanceof PDO) {
  die("db() exists but did not return PDO");
}

echo "DB OK ✅";