exec($sql); } function listWorlds(int $limit = 10): array { $stmt = db()->prepare('SELECT id, name, size, updated_at FROM worlds ORDER BY updated_at DESC LIMIT :limit'); $stmt->bindValue(':limit', $limit, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetchAll(); } function getWorldById(int $id): ?array { $stmt = db()->prepare('SELECT id, name, size, world_json, created_at, updated_at FROM worlds WHERE id = :id'); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); $row = $stmt->fetch(); return $row ?: null; } function saveWorld(string $name, string $worldJson, int $size): int { $stmt = db()->prepare('INSERT INTO worlds (name, size, world_json) VALUES (:name, :size, :world_json)'); $stmt->bindValue(':name', $name); $stmt->bindValue(':size', $size, PDO::PARAM_INT); $stmt->bindValue(':world_json', $worldJson); $stmt->execute(); return (int)db()->lastInsertId(); }