PHP - 如何在查询中使用 strtolower

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6852849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:28:09  来源:igfitidea点击:

PHP - How to use strtolower in query

phplowercase

提问by Daniel

In database I have this field: "TeST" and I dont know where are the caps lock and I just want to strtolower him and to do somthing like that

在数据库中,我有这个字段:“ Test”,我不知道大写锁定在哪里,我只是想降低他并做类似的事情

SELECT * FROM table WHERE strtolower(field) = strtolower($var)

How can I do that?

我怎样才能做到这一点?

回答by Phil

Using PDO and assuming MySQL

使用 PDO 并假设 MySQL

$stmt = $db->prepare('SELECT * FROM table WHERE LOWER(`field`) = ?');
$stmt->execute(array(strtolower($var)));

回答by Wrikken

In MySQL, the function is called LOWERThen again, you can just use a case-insensitive collation on the field or in the query, and it will match regardless of case, which seems the better option.

在 MySQL 中,该函数被调用LOWER然后再次,您可以在字段或查询中使用不区分大小写的排序规则,无论大小写,它都会匹配,这似乎是更好的选择。

回答by Vi8L

Simply use :

只需使用:

"SELECT * FROM `table_name` WHERE LOWER(`field_name`)='".strtolower($_var)."'";

Or Use

或使用

"SELECT * FROM `table_name` WHERE LCASE(`field_name`)='".strtolower($_var)."'";

Both functions works same

两个功能的工作原理相同

回答by Lovepreet Singh

LOWERfunction in mysql can be used to convert field value to lower case. eg:

LOWERmysql 中的函数可用于将字段值转换为小写。例如:

"select * from table_name where LOWER(email) = ?";