Compare commits
1 Commits
2.2.1
...
9ec9fdd731
Author | SHA1 | Date | |
---|---|---|---|
9ec9fdd731 |
@ -11,10 +11,5 @@
|
|||||||
"email": "aldarien85@gmail.com"
|
"email": "aldarien85@gmail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {},
|
"require": {}
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"ProVM\\": "src/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,5 @@ interface ResultSet
|
|||||||
public function execute(array $values): ResultSet;
|
public function execute(array $values): ResultSet;
|
||||||
public function getAsArray(): array;
|
public function getAsArray(): array;
|
||||||
public function getAsObject(): array;
|
public function getAsObject(): array;
|
||||||
public function getFirstAsArray(): array;
|
public function getFirst(): mixed;
|
||||||
public function getFirstAsObject(): object;
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
<?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,7 +4,6 @@ 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
|
||||||
{
|
{
|
||||||
@ -32,34 +31,14 @@ class ResultSet implements RSInterface
|
|||||||
|
|
||||||
public function getAsArray(): array
|
public function getAsArray(): array
|
||||||
{
|
{
|
||||||
$rs = $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
|
return $this->getStatement()->fetchAll(PDO::FETCH_ASSOC);
|
||||||
if (!$rs) {
|
|
||||||
throw new BlankResult();
|
|
||||||
}
|
|
||||||
return $rs;
|
|
||||||
}
|
}
|
||||||
public function getAsObject(): array
|
public function getAsObject(): array
|
||||||
{
|
{
|
||||||
$rs = $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
|
return $this->getStatement()->fetchAll(PDO::FETCH_OBJ);
|
||||||
if (!$rs) {
|
|
||||||
throw new BlankResult();
|
|
||||||
}
|
|
||||||
return $rs;
|
|
||||||
}
|
}
|
||||||
public function getFirstAsArray(): array
|
public function getFirst(): mixed
|
||||||
{
|
{
|
||||||
$rs = $this->getStatement()->fetch(PDO::FETCH_ASSOC);
|
return $this->getStatement()->fetch(PDO::FETCH_OBJ);
|
||||||
if (!$rs or count($rs) === 0) {
|
|
||||||
throw new BlankResult();
|
|
||||||
}
|
|
||||||
return $rs;
|
|
||||||
}
|
|
||||||
public function getFirstAsObject(): object
|
|
||||||
{
|
|
||||||
$rs = $this->getStatement()->fetch(PDO::FETCH_OBJ);
|
|
||||||
if (!$rs or count($rs) === 0) {
|
|
||||||
throw new BlankResult();
|
|
||||||
}
|
|
||||||
return $rs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
<?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