如何在PHP/MySQL中使SELECT不区分大小写? [英] How to make a SELECT in PHP/MySQL case insensitive?

查看:86
本文介绍了如何在PHP/MySQL中使SELECT不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

她是我的问题,我想这真的很基本.

Her's my probleme, i guess its really basic.

我正在尝试在数据库中查找是否存在一行.这是我的代码:

I'm trying to lookup in the database if a line does exist. heres my code :

$req="SELECT * FROM INSTITUTS WHERE inst_name='$fc_inst'";
$result=mysql_query($req) or die ('Erreur :'.mysql_error());
if (mysql_num_rows($result)){
echo '  name exist';
}
else {
echo '  does not exist.';
}

问题是,当我寻找测试"时,即使我的数据库中有测试",它也说不存在.

Probleme is, when imm looking for "test", it says does not exist, even if i have "Test" in my database.

推荐答案

您可以使用LIKE:

WHERE foo LIKE 'bar'

或者您可以将以下两个字母都转换为小写字母:

Or you can cast both lowercase with:

WHERE LOWER(foo) = LOWER("bar")

使用LOWER()的示例最有效,因为您知道数据库中的所有数据均已小写,然后可以执行:

The example with LOWER() is most effective where you know that all of your data in the database is already lower cased and then you can just execute:

WHERE foo = LOWER("bar")

如果可以小写数据库中的所有数据,则此价格比LIKE便宜.

This would be a cheaper comparison than the LIKE if you can lower case all of the data in your database.

这篇关于如何在PHP/MySQL中使SELECT不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆