PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } catch (PDOException $e) { // In a real app, you'd log this error and show a generic message. // For now, we'll just die and show the error. die("Database connection failed: " . $e->getMessage()); } } return $pdo; } // A simple function to run migrations. // In a real application, you would use a more robust migration tool. function run_migrations() { $pdo = db(); $migration_dir = __DIR__ . '/migrations'; $files = glob($migration_dir . '/*.sql'); foreach ($files as $file) { try { $sql = file_get_contents($file); $pdo->exec($sql); } catch (Exception $e) { // Log error or handle it error_log("Failed to run migration: $file. Error: " . $e->getMessage()); } } } // Automatically run migrations when this file is included. // This is for simplicity in this development environment. if (DB_HOST !== 'YOUR_SUPABASE_HOST') { // Don't run if not configured run_migrations(); }