Инициализация проекта
Загрузка проекта на 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;
|
||||
}
|
||||
}
|
||||
2311
backend/app/class/database/class_Medoo.php
Normal file
2311
backend/app/class/database/class_Medoo.php
Normal file
File diff suppressed because it is too large
Load Diff
19
backend/app/config.php
Normal file
19
backend/app/config.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Подключение классов базы данных
|
||||
require_once __DIR__ . '/class/database/class_Medoo.php';
|
||||
require_once __DIR__ . '/class/database/class_Database.php';
|
||||
|
||||
// Подключение классов Функций
|
||||
require_once __DIR__ . '/functions/function.php';
|
||||
require_once __DIR__ . '/functions/routing.php';
|
||||
|
||||
// Данные подключения к БД
|
||||
define('DB_HOST', '192.168.1.9');
|
||||
define('DB_USER', 'root');
|
||||
define('DB_PASS', 'root');
|
||||
define('DB_NAME', 'taskboard');
|
||||
define('DB_PORT', 3306);
|
||||
define('DB_CHARSET', 'utf8mb4');
|
||||
|
||||
?>
|
||||
4
backend/app/functions/function.php
Normal file
4
backend/app/functions/function.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
|
||||
?>
|
||||
19
backend/app/functions/routing.php
Normal file
19
backend/app/functions/routing.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Функция роутинга API
|
||||
function handleRouting($routes = []) {
|
||||
|
||||
$request = $_SERVER['REQUEST_URI'];
|
||||
$path = parse_url($request, PHP_URL_PATH);
|
||||
|
||||
if (isset($routes[$path])) {
|
||||
|
||||
$file_path = $routes[$path];
|
||||
global $_POST, $_FILES, $_SERVER, $_GET;
|
||||
include $file_path;
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
16
backend/index.php
Normal file
16
backend/index.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/app/config.php';
|
||||
|
||||
// Игнорируем запросы к favicon.ico и другим статическим файлам
|
||||
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
||||
if (preg_match('/\.(ico|png|jpg|jpeg|gif|css|js|svg|woff|woff2|ttf|eot)$/i', $requestUri)) {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$accounts = Database::select('accounts', '*');
|
||||
|
||||
echo json_encode([$accounts]);
|
||||
Reference in New Issue
Block a user