Ok first I thought you were confused. Now I know you are just out right stupid. I am going to add comments to both queries to make it more like pseudocode. So pay attention.
Original Query:
Code:
SELECT u.*, b.expire, b.reason # Selects all the columns from the 'users' table and two columns from the 'bans' table.
FROM users AS u # Choosing the 'users' table to select the columns from. Setting alias 'u'.
LEFT JOIN bans AS b # Loading all the results from the 'bans' table. Setting alias 'b'.
ON ( u.username = b.value OR b.value = ? ) AND ( UNIX_TIMESTAMP() - b.expire < 0 ) # Matching only results from 'users' table that has a username of the 'bans' table value column. Ensuring unix timestamp is not expired (I do not know why he did that check in this part of the query...).
WHERE u.username = ? # Where the username is the first parameter...
AND u.password = ? # ... and the password is the second parameter.
LIMIT 1; # Only display the first returned row from the query.
New Query: (suggested query pseudo)
Code:
SELECT u.*, b.expire, b.reason # Selects all the columns from the 'users' table and two columns from the 'bans' table.
FROM users u # Choosing the 'users' table to select the columns from. Setting alias 'u'.
INNER JOIN bans b # Loading conditional results (condition below). Setting alias 'b'.
ON u.username = b.value # Only grabbing pair matches in both tables, condition is username.
WHERE u.username = ? # Where the username is the first parameter...
AND u.password = ? # ... and the password is the second parameter...
AND (UNIX_TIMESTAMP() - b.expire) < 0 # ... and the unix timestamp minus expiration is less than 0 (expired).
ORDER BY b.id DESC # Order ban results in descending order to get the most recent ban.
LIMIT 0,1; # Only display the first returned row from the query.