setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::createTables(); } catch (PDOException $e) { error_log("Database connection failed: " . $e->getMessage()); // Verbeterde foutmelding voor de gebruiker die("FATAL ERROR: Database connection failed. This is often a permission issue.
Error: " . $e->getMessage() . "
Database Path: " . self::$dbFile . "
Please ensure the web server user (www-data) has write permissions to the database file and its directory."); } } return self::$instance; } private static function createTables(): void { $db = self::getInstance(); $db->exec('CREATE TABLE IF NOT EXISTS categories ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, parent_id INTEGER DEFAULT NULL )'); $db->exec('CREATE TABLE IF NOT EXISTS items ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, category_id INTEGER, FOREIGN KEY (category_id) REFERENCES categories(id) )'); } }