up
This commit is contained in:
16
public/api/_db.php
Executable file
16
public/api/_db.php
Executable file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// public/api/_db.php
|
||||
$cfg = require __DIR__ . '/../../src/config.php';
|
||||
$dsn = "mysql:host={$cfg['db_host']};dbname={$cfg['db_name']};charset={$cfg['db_charset']}";
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
];
|
||||
try {
|
||||
$pdo = new PDO($dsn, $cfg['db_user'], $cfg['db_pass'], $options);
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['error' => 'DB connection failed']);
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user