Initial commit

This commit is contained in:
Ivan Petrov
2025-12-24 19:19:01 +03:00
commit a7097c6178
19493 changed files with 94306 additions and 0 deletions

47
engine/class.database.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
defined('ROOT_DIR') || exit;
class DB {
public string $db_host;
public string $db_name;
public string $db_user;
public string $db_password;
private PDO $dbh;
public function __construct($db_host, $db_name, $db_user, $db_password)
{
$this->db_host = $db_host;
$this->db_name = $db_name;
$this->db_user = $db_user;
$this->db_password = $db_password;
}
public function connect(): DB
{
$this->dbh = new PDO("mysql:host=". $this->db_host. ";dbname=" . $this->db_name . ";charset=utf8mb4", $this->db_user, $this->db_password);
return $this;
}
// Запрос на получение информации из базы
public function query($query, $params)
{
log_message("Начало запроса");
log_message($query);
log_message(json_encode($params));
log_message("Конец запроса");
$sth = $this->dbh->prepare($query);
$sth->execute($params);
return $sth->fetchAll();
}
// Запрос на сохранение данных в базу
public function insert($query, $params)
{
$sth = $this->dbh->prepare($query);
$sth->execute($params);
return $this->dbh->lastInsertId();
}
}