pdo = $pdo; # SOllte bereits aus den Options kommen! #$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); #$this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC); } public function execute(SqlQuery $query): int { try { $statement = $this->pdo->prepare($query->sql); $statement->execute($query->parameters->toPdoArray()); return $statement->rowCount(); } catch (\PDOException $e) { throw DatabaseException::simple("Failed to execute query: {$e->getMessage()}", $e); } } public function query(SqlQuery $query): ResultInterface { try { $statement = $this->pdo->prepare($query->sql); $statement->execute($query->parameters->toPdoArray()); return new PdoResult($statement); } catch (\PDOException $e) { $debug = $query->toDebugString(); throw DatabaseException::simple("Failed to execute query: {$e->getMessage()} --- Debug: {$debug}", $e); } } public function queryOne(SqlQuery $query): ?array { $result = $this->query($query); return $result->fetch(); } public function queryColumn(SqlQuery $query): array { $result = $this->query($query); return $result->fetchColumn(); } public function queryScalar(SqlQuery $query): mixed { $result = $this->query($query); return $result->fetchScalar(); } public function beginTransaction(): void { try { $this->pdo->beginTransaction(); } catch (\PDOException $e) { throw DatabaseException::simple("Failed to begin transaction: {$e->getMessage()}", $e); } } public function commit(): void { try { $this->pdo->commit(); } catch (\PDOException $e) { throw DatabaseException::simple("Failed to commit transaction: {$e->getMessage()}", $e); } } public function rollback(): void { try { $this->pdo->rollBack(); } catch (\PDOException $e) { throw DatabaseException::simple("Failed to rollback transaction: {$e->getMessage()}", $e); } } public function inTransaction(): bool { return $this->pdo->inTransaction(); } public function lastInsertId(): string { return $this->pdo->lastInsertId(); } public function getPdo(): \PDO { return $this->pdo; } }