Compare commits
6 Commits
ac9b141928
...
2.2.1
Author | SHA1 | Date | |
---|---|---|---|
fb37211f7d | |||
a326904825 | |||
816d8f7b9c | |||
2c6c0e6e55 | |||
b964bd65fe | |||
cc7cd638e3 |
11
src/Database/Exception.php
Normal file
11
src/Database/Exception.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace ProVM\Database;
|
|||||||
use PDO;
|
use PDO;
|
||||||
use PDOStatement;
|
use PDOStatement;
|
||||||
use ProVM\Concept\Database\ResultSet as RSInterface;
|
use ProVM\Concept\Database\ResultSet as RSInterface;
|
||||||
|
use ProVM\Exception\BlankResult;
|
||||||
|
|
||||||
class ResultSet implements RSInterface
|
class ResultSet implements RSInterface
|
||||||
{
|
{
|
||||||
@ -31,18 +32,34 @@ class ResultSet implements RSInterface
|
|||||||
|
|
||||||
public function getAsArray(): array
|
public function getAsArray(): array
|
||||||
{
|
{
|
||||||
return $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
|
$rs = $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
if (!$rs) {
|
||||||
|
throw new BlankResult();
|
||||||
|
}
|
||||||
|
return $rs;
|
||||||
}
|
}
|
||||||
public function getAsObject(): array
|
public function getAsObject(): array
|
||||||
{
|
{
|
||||||
return $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
|
$rs = $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
|
||||||
|
if (!$rs) {
|
||||||
|
throw new BlankResult();
|
||||||
|
}
|
||||||
|
return $rs;
|
||||||
}
|
}
|
||||||
public function getFirstAsArray(): array
|
public function getFirstAsArray(): array
|
||||||
{
|
{
|
||||||
return $this->getStatement()->fetch(PDO::FETCH_ASSOC);
|
$rs = $this->getStatement()->fetch(PDO::FETCH_ASSOC);
|
||||||
|
if (!$rs or count($rs) === 0) {
|
||||||
|
throw new BlankResult();
|
||||||
|
}
|
||||||
|
return $rs;
|
||||||
}
|
}
|
||||||
public function getFirstAsObject(): object
|
public function getFirstAsObject(): object
|
||||||
{
|
{
|
||||||
return $this->getStatement()->fetch(PDO::FETCH_OBJ);
|
$rs = $this->getStatement()->fetch(PDO::FETCH_OBJ);
|
||||||
|
if (!$rs or count($rs) === 0) {
|
||||||
|
throw new BlankResult();
|
||||||
|
}
|
||||||
|
return $rs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
src/Exception/BlankResult.php
Normal file
15
src/Exception/BlankResult.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user