10 Commits
2.0.0 ... 2.2.0

5 changed files with 58 additions and 6 deletions

View File

@ -11,5 +11,10 @@
"email": "aldarien85@gmail.com"
}
],
"require": {}
"require": {},
"autoload": {
"psr-4": {
"ProVM\\": "src/"
}
}
}

View File

@ -9,5 +9,6 @@ interface ResultSet
public function execute(array $values): ResultSet;
public function getAsArray(): array;
public function getAsObject(): array;
public function getFirst(): mixed;
public function getFirstAsArray(): array;
public function getFirstAsObject(): object;
}

View File

@ -0,0 +1,11 @@
<?php
namespace ProVM\Database;
class Exception extends \Exception
{
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
$code += 300;
parent::__construct($message, $code, $previous);
}
}

View File

@ -31,14 +31,34 @@ class ResultSet implements RSInterface
public function getAsArray(): array
{
return $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
$rs = $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
if (!$rs) {
throw new \PDOException("No results found.");
}
return $rs;
}
public function getAsObject(): array
{
return $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
$rs = $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
if (!$rs) {
throw new \PDOException("No results found.");
}
return $rs;
}
public function getFirst(): mixed
public function getFirstAsArray(): array
{
return $this->getStatement()->fetch(PDO::FETCH_OBJ);
$rs = $this->getStatement()->fetch(PDO::FETCH_ASSOC);
if (!$rs or count($rs) === 0) {
throw new \PDOException("No results found.");
}
return $rs;
}
public function getFirstAsObject(): object
{
$rs = $this->getStatement()->fetch(PDO::FETCH_OBJ);
if (!$rs or count($rs) === 0) {
throw new \PDOException("No results found.");
}
return $rs;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace ProVM\Exception;
use ProVM\Database\Exception;
use Throwable;
class BlankResult extends Exception
{
public function __construct(?Throwable $previous = null)
{
$message = "No results found";
$code = 0;
parent::__construct($message, $code, $previous);
}
}