pdo = new PDO( $config['dsn'], $config['username'] ?? null, $config['password'] ?? null, $config['options'] ?? [] ); } public function pdo(): PDO { return $this->pdo; } public function query(string $sql, array $parameters = []): array { $statement = $this->pdo->prepare($sql); $statement->execute($parameters); return array_map([$this, 'resolveStreams'], $statement->fetchAll(PDO::FETCH_ASSOC)); } private function resolveStreams(array $row): array { return array_map( static fn($v) => is_resource($v) ? (stream_get_contents($v) ?: '') : $v, $row ); } public function first(string $sql, array $parameters = []): ?array { $rows = $this->query($sql, $parameters); return $rows[0] ?? null; } public function execute(string $sql, array $parameters = []): bool { $statement = $this->pdo->prepare($sql); return $statement->execute($parameters); } }