Основные классы переехали на обёртку PDO. Плановое №16.

This commit is contained in:
lopar
2021-01-28 23:05:34 +02:00
parent 0099c235a7
commit 8402912098
22 changed files with 284 additions and 1940 deletions
+41 -1
View File
@@ -13,13 +13,20 @@ class DBPDO
public $pdo;
private $error;
private static $_instance = null;
function __construct()
{
$this->connect();
}
public static function INIT(): DBPDO
{
if (!self::$_instance) {
self::$_instance = new DBPDO();
}
return self::$_instance;
}
function prep_query($query)
{
@@ -102,6 +109,39 @@ class DBPDO
return $results;
}
function ofetch($query, $values = null)
{
if ($values == null) {
$values = array();
} else if (!is_array($values)) {
$values = array($values);
}
$stmt = $this->execute($query, $values);
return $stmt->fetch(PDO::FETCH_OBJ);
}
function ofetchAll($query, $values = null, $key = null)
{
if ($values == null) {
$values = array();
} else if (!is_array($values)) {
$values = array($values);
}
$stmt = $this->execute($query, $values);
$results = $stmt->fetchAll(PDO::FETCH_OBJ);
// Allows the user to retrieve results using a
// column from the results as a key for the array
if ($key != null && $results[0][$key]) {
$keyed_results = array();
foreach ($results as $result) {
$keyed_results[$result[$key]] = $result;
}
$results = $keyed_results;
}
return $results;
}
function lastInsertId()
{
return $this->pdo->lastInsertId();