I want to get the contents from a row in the database and compare the lowercase version of it to a lowercase version of a user imput to check if it exists in the database:
"SELECT `id` FROM `user_accounts` WHERE `username` = '".strtolower($username)."'"
How can i get username to be lowercase from mysql?
The LOWER() function converts a string to lower-case. Note: The LCASE() function is equal to the LOWER() function.
Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case-sensitive. This works only on file systems that are not case-sensitive!
If you want case-insensitive distinct, you need to use UPPER() or LOWER().
By default, it depends on the operating system and its case sensitivity. This means MySQL is case-insensitive in Windows and macOS, while it is case-sensitive in most Linux systems. However, you can change the behavior by changing collation.
As answered above, Ideally this should work,
$query = "SELECT `id`
FROM `user_accounts`
WHERE LOWER(`username`) = '".strtolower($username)."'";
but it won't work if the "username" column in "user_accounts" table is defined as VARBINARY. The reason is VARBINARY requires the data to be case sensitive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With