简体   繁体   中英

not case sensitive query in mysql

i need to query my database and find results :

mysql_query("select * from ".ALU_TABLE." where username like '%$q%' or name like '%$q%'");

if i have a name in my table such as Book and i enter book in search box it wont show the Book

i need to query my database as not to be case sensitive.

您可以使用LOWER()函数

... WHERE LOWER(username) LIKE blabl OR LOWER(name) LIKE asdasd

You need to append something like COLLATE utf8_general_ci to your query. (The _ci suffix stands for case insensitive.)

Have a look at the documentation: 9.1.7.1. Using COLLATE in SQL Statements :

With the COLLATE clause, you can override whatever the default collation is for a comparison. COLLATE may be used in various parts of SQL statements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM