45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?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);
|
|
}
|
|
}
|