private function write()
    {
        $sessionData['data'] = $this->data;
        $sessionData['flash'] = $this->newFlashData;

        // Write session data to database
        $stmt = $this->db->prepare("UPDATE {$this->tableName} SET data = ? WHERE session_id = ?");
        $stmt->execute([json_encode($sessionData), $this->sessionId]);
    }