Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - How to use strtolower in query

Tags:

php

lowercase

In a database I have this field: "TeST". I don’t know where the upper case characters are. I just want to strtolower them and do something like this:

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

How can I do that?

like image 707
Daniel Avatar asked Jul 28 '11 00:07

Daniel


1 Answers

Using PDO and assuming MySQL

$stmt = $db->prepare('SELECT * FROM table WHERE LOWER(`field`) = ?');
$stmt->execute(array(strtolower($var)));
like image 68
Phil Avatar answered Oct 10 '22 08:10

Phil