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?
我怎样才能做到这一点?
4 个解决方案
#1
39
Using PDO and assuming MySQL
使用PDO并假设MySQL
$stmt = $db->prepare('SELECT * FROM table WHERE LOWER(`field`) = ?');
$stmt->execute(array(strtolower($var)));
#2
8
In MySQL, the function is called LOWER
Then 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然后,您可以在字段或查询中使用不区分大小写的排序规则,无论大小写都匹配,这似乎是更好的选择。
#3
5
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
两种功能都相同
#4
3
LOWER
function in mysql can be used to convert field value to lower case. eg:
mysql中的LOWER函数可用于将字段值转换为小写。例如:
"select * from table_name where LOWER(email) = ?";
#1
39
Using PDO and assuming MySQL
使用PDO并假设MySQL
$stmt = $db->prepare('SELECT * FROM table WHERE LOWER(`field`) = ?');
$stmt->execute(array(strtolower($var)));
#2
8
In MySQL, the function is called LOWER
Then 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然后,您可以在字段或查询中使用不区分大小写的排序规则,无论大小写都匹配,这似乎是更好的选择。
#3
5
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
两种功能都相同
#4
3
LOWER
function in mysql can be used to convert field value to lower case. eg:
mysql中的LOWER函数可用于将字段值转换为小写。例如:
"select * from table_name where LOWER(email) = ?";