<?php
declare(strict_types=1);
namespace classes;
use PDO;
use PDOException;
class DataBase extends PDO
{
public object $connection;
public function __construct()
{
try {
$cnf = require ROOT . '/config/db.php';
$this->connection = new PDO('mysql:host='.$cnf['host'].';dbname=' . $cnf['name'], $cnf['user'], $cnf['password']);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
public function insert(string $sql, array $execute = []): void
{
$stmt = $this->connection->prepare($sql);
$stmt->execute($execute);
}
public function rows(string $sql, array $execute = [])
{
$sth = $this->connection->prepare($sql);
$sth->execute($execute);
return $sth->fetchAll(PDO::FETCH_ASSOC);
}
public function lastId()
{
return $this->connection->lastInsertId();
}
}