Files
database/src/Database/ResultSet.php

45 lines
1.0 KiB
PHP
Raw Normal View History

2022-09-08 20:02:05 -04:00
<?php
namespace ProVM\Database;
use PDO;
use PDOStatement;
use ProVM\Concept\Database\ResultSet as RSInterface;
class ResultSet implements RSInterface
{
public function __construct(PDOStatement $statement)
{
$this->setStatement($statement);
}
protected PDOStatement $statement;
public function setStatement(PDOStatement $statement): RSInterface
{
$this->statement = $statement;
return $this;
}
public function getStatement(): PDOStatement
{
return $this->statement;
}
public function execute(array $values): RSInterface
{
$this->getStatement()->execute($values);
return $this;
}
public function getAsArray(): array
{
return $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
}
public function getAsObject(): array
{
return $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
}
public function getFirst(): mixed
{
return $this->getStatement()->fetch(PDO::FETCH_OBJ);
}
}