You didn't mention what database you're using, so I won't go out on a limb there.
The way to do this -- as you have correctly figured -- is on the database side (yes, can be done in code, but messy and ... why bother??).
The syntax varies from database to database, but this example should give you a direction: It says give me the user's permission level where there is a match between user-supplied (via a form, say) username with one store in the database:
SELECT
user_access_level
FROM
user_profile
WHERE
lower(username) = lower($username)
Note that the suggestion to user the LIKE operator will NOT work for POSIX complient DBs. MS SQL Server, on the other hand, is case-insensitive, so "Ralph" = "RAlpH" = "ralph" and so on.
The deal here is to lowercase (lower) each side of the equal statement so case is not an issue.
Hope this helps; ding me if it does not.