What are the best practices for structuring PHP classes related to user authentication and database interactions?

Issue: When dealing with user authentication and database interactions in PHP, it is best practice to separate concerns by creating separate classes for each functionality. This helps in maintaining a clean and organized codebase, as well as improving code reusability and testability.

class UserAuthentication {
    public function login($username, $password) {
        // Validate user credentials
        // Check if user exists in the database
        // Set session variables upon successful login
    }

    public function logout() {
        // Destroy session variables
    }

    public function isLoggedIn() {
        // Check if user is logged in
    }
}

class DatabaseInteraction {
    private $connection;

    public function __construct($host, $username, $password, $database) {
        $this->connection = new mysqli($host, $username, $password, $database);
    }

    public function query($sql) {
        // Execute SQL query
        // Return result set
    }

    public function execute($sql) {
        // Execute SQL query
        // Return boolean based on success
    }
}