Ist die checkBann() Methode zu kompliziert und wie könnte sie vereinfacht werden, z.B. durch die Verwendung von SQL-Triggern?

The checkBann() method may be too complicated and could be simplified by using SQL triggers to automatically check for banned users. By creating a trigger in the database that checks for banned users upon certain actions (such as login or accessing restricted content), the need for a complex checkBann() method in the PHP code can be eliminated.

// Example of creating a SQL trigger to check for banned users upon login
CREATE TRIGGER check_banned_user
BEFORE INSERT ON login_table
FOR EACH ROW
BEGIN
    DECLARE is_banned INT;
    SELECT COUNT(*) INTO is_banned FROM banned_users WHERE user_id = NEW.user_id;
    IF is_banned > 0 THEN
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'User is banned';
    END IF;
END;