- First draft of current WIP
This commit is contained in:
commit
b73d046e0a
47 files changed
+2797
No files matched your search
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Ulmus\Common;
|
||||
|
||||
use PDO, PDOStatement;
|
||||
|
||||
class PdoObject extends PDO {
|
||||
|
||||
public function select(string $sql, array $parameters = []) : PDOStatement
|
||||
{
|
||||
try {
|
||||
if ( $statement = $this->prepare($sql) ) {
|
||||
$statement = $this->execute($statement, $parameters, true);
|
||||
$statement->setFetchMode(\PDO::FETCH_ASSOC);
|
||||
return $statement;
|
||||
}
|
||||
} catch (\PDOException $e) { throw $e; }
|
||||
}
|
||||
|
||||
public function execute(PDOStatement $statement, array $parameters = [], bool $commit = true) : ? PDOStatement
|
||||
{
|
||||
try {
|
||||
if (! $this->inTransaction() ) {
|
||||
$this->beginTransaction();
|
||||
}
|
||||
|
||||
if ( empty($parameters) ? $statement->execute() : $statement->execute($parameters) ) {
|
||||
# if ( $commit ) {
|
||||
$this->commit();
|
||||
# }
|
||||
|
||||
return $statement;
|
||||
}
|
||||
else {
|
||||
throw new PDOException('Could not begin transaction or given statement is invalid.');
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
$this->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user