PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ]); } function run_migrations($pdo) { $migration_dir = __DIR__ . '/migrations'; if (!is_dir($migration_dir)) return; $files = glob($migration_dir . '/*.sql'); sort($files); foreach ($files as $file) { try { $sql = file_get_contents($file); if (!empty(trim($sql))) { $pdo->exec($sql); } } catch (PDOException $e) { // Log error or handle it, but don't stop other migrations error_log("Migration failed for file: " . basename($file) . " with error: " . $e->getMessage()); } } } // Run migrations on connection run_migrations($pdo); return $pdo; }