Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    Colorado
    Posts
    132
    Thanks
    7
    Thanked 1 Time in 1 Post

    Ignore case when selecting

    Hey, I have a users DB, that contains a username and a password. If I have a user "User", I want them to be able to login using "user", or "UsEr" or anything...
    Obviously I can set my $var to strtolower($var), but I dont know how to select in mysql and ignore the case.
    -bubbles

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    mysql is case insensitive by default.

  • #3
    Regular Coder
    Join Date
    Oct 2006
    Posts
    181
    Thanks
    1
    Thanked 6 Times in 6 Posts
    if the strtolower is active before the members join up, then they will be saved in lowercase, so if then u use strtolower when logging on it will set to lower case also..

    the only problem is setting all the current members to lowerstring, maybe make some sort of script, depending on the size of the members list
    Quote Originally Posted by Excavator
    write it for firefox then hack it for IE

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    It doesn't matter if they are stored in lower, upper or mixed case. Mysql is case insensitive.

    Dave, dave, DaVE, daVE, DavE are all equivalent and will all be found by:

    Code:
    select 
    name
    from testtable
    where name='DaVE'
    so you don't need toupper, tolower or anything else.

  • #5
    Regular Coder
    Join Date
    Oct 2006
    Posts
    181
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by guelphdad View Post
    mysql is case insensitive by default.
    Rofl... yeah, i misread your post, i thought you said Case Sensitive..
    Quote Originally Posted by Excavator
    write it for firefox then hack it for IE

  • #6
    New Coder
    Join Date
    Feb 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for going a bit offtopic, but what if I wanted it to be case-sensitive?
    Jozef "Lord Emperor" Jirasek

    English is my second language, excuse any mistakes I make.

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    From the mysql manual -
    The BINARY operator casts the string following it to a binary string. This is an easy way to force a column comparison to be done byte by byte rather than character by character. This causes the comparison to be case sensitive even if the column isn't defined as BINARY or BLOB. BINARY also causes trailing spaces to be significant.

    mysql> SELECT 'a' = 'A';
    -> 1
    mysql> SELECT BINARY 'a' = 'A';
    -> 0
    mysql> SELECT 'a' = 'a ';
    -> 1
    mysql> SELECT BINARY 'a' = 'a ';
    -> 0
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •