Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
require_once __DIR__ . '/../config/config.php';
require_once dirname(__DIR__) . '/config/config.php'; // updated path
// (optional safety)
if (!defined('DB_HOST')) {
throw new RuntimeException('Database config not loaded. Check config/config.php path.');
}
class Database {
private static $instance = null;
private $pdo;
private function __construct() {
foreach (['DB_HOST','DB_NAME','DB_USER','DB_PASS'] as $c) {
if (!defined($c)) {
throw new RuntimeException("Missing database config constant: $c");
}
}
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4';
try {
$this->pdo = new PDO($dsn, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $e) {
throw new RuntimeException('Database connection failed: ' . $e->getMessage());
}
}
public static function getInstance(): self {
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function getConnection(): PDO {
return $this->pdo;
}
}