Инициализация проекта
Загрузка проекта на GIT
This commit is contained in:
40
backend/app/class/database/class_Database.php
Normal file
40
backend/app/class/database/class_Database.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Medoo\Medoo;
|
||||
|
||||
class Database
|
||||
{
|
||||
public static $db;
|
||||
|
||||
// Магический метод для вызова методов класса Medoo
|
||||
public static function __callStatic($name, $arguments) {
|
||||
if (!self::$db) {
|
||||
self::init();
|
||||
}
|
||||
|
||||
return call_user_func_array([self::$db, $name], $arguments);
|
||||
}
|
||||
|
||||
// Инициализация подключения к БД
|
||||
public static function init() {
|
||||
if (!self::$db) {
|
||||
try {
|
||||
self::$db = new Medoo([
|
||||
'type' => 'mysql',
|
||||
'host' => DB_HOST,
|
||||
'database' => DB_NAME,
|
||||
'username' => DB_USER,
|
||||
'password' => DB_PASS,
|
||||
'port' => DB_PORT,
|
||||
'charset' => DB_CHARSET,
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'error' => \PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
} catch (\PDOException $e) {
|
||||
die('Ошибка подключения к БД: ' . $e->getMessage());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
return self::$db;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user