asd
This commit is contained in:
@@ -2,9 +2,13 @@
|
|||||||
try {
|
try {
|
||||||
require_once __DIR__ . '/../../tools/db.php';
|
require_once __DIR__ . '/../../tools/db.php';
|
||||||
$pdo = tools_build_pdo();
|
$pdo = tools_build_pdo();
|
||||||
} catch (PDOException $e) {
|
} catch (Throwable $e) {
|
||||||
http_response_code(500);
|
http_response_code(500);
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
echo json_encode(['error' => 'DB connection failed']);
|
$payload = ['error' => 'DB connection failed'];
|
||||||
|
if (getenv('APP_DEBUG') === '1') {
|
||||||
|
$payload['detail'] = $e->getMessage();
|
||||||
|
}
|
||||||
|
echo json_encode($payload, JSON_UNESCAPED_UNICODE);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,15 @@
|
|||||||
function tools_build_pdo(): PDO
|
function tools_build_pdo(): PDO
|
||||||
{
|
{
|
||||||
$cfg = require __DIR__ . '/../src/config.php';
|
$cfg = require __DIR__ . '/../src/config.php';
|
||||||
|
if (!is_array($cfg)) {
|
||||||
|
throw new RuntimeException('DB config did not return an array.');
|
||||||
|
}
|
||||||
|
$required = ['db_host', 'db_name', 'db_user', 'db_pass', 'db_charset'];
|
||||||
|
foreach ($required as $key) {
|
||||||
|
if (!array_key_exists($key, $cfg)) {
|
||||||
|
throw new RuntimeException('Missing DB config key: ' . $key);
|
||||||
|
}
|
||||||
|
}
|
||||||
$dsn = "mysql:host={$cfg['db_host']};dbname={$cfg['db_name']};charset={$cfg['db_charset']}";
|
$dsn = "mysql:host={$cfg['db_host']};dbname={$cfg['db_name']};charset={$cfg['db_charset']}";
|
||||||
$options = [
|
$options = [
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
|||||||
Reference in New Issue
Block a user