1
1
mirror of https://github.com/xodivorce/isdowndetectordown.git synced 2025-12-20 02:19:33 +05:30

(chore): initial MVP release

This commit is contained in:
2025-11-21 14:41:07 +05:30
commit ebaf5cb698
117 changed files with 15381 additions and 0 deletions

56
core/connection.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
// core/connection.php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Dotenv\Dotenv;
// Load .env from project root
$dotenv = Dotenv::createImmutable(dirname(__DIR__));
$dotenv->load();
date_default_timezone_set('Asia/Kolkata');
function env(string $key, ?string $default = null): ?string
{
return $_ENV[$key] ?? $_SERVER[$key] ?? $default;
}
$debug = filter_var(env('APP_DEBUG', 'false'), FILTER_VALIDATE_BOOLEAN);
ini_set('display_errors', $debug ? '1' : '0');
ini_set('display_startup_errors', $debug ? '1' : '0');
error_reporting(
$debug ? E_ALL : (E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT)
);
try {
$pdo = new PDO(
sprintf(
'mysql:host=%s;dbname=%s;charset=utf8mb4',
env('DB_HOST', '127.0.0.1'),
env('DB_NAME', 'isdowndetectordown')
),
env('DB_USER', 'root'),
env('DB_PASS', ''),
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
);
} catch (PDOException $e) {
http_response_code(500);
echo 'DB connection failed';
if ($debug) {
echo ': ' . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8');
}
exit;
}
function db(): PDO
{
global $pdo;
return $pdo;
}