PHP - How to use strtolower in query

Daniel picture Daniel · Jul 28, 2011 · Viewed 36k times · Source

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

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

How can I do that?

Answer

Phil picture Phil · Jul 28, 2011

Using PDO and assuming MySQL

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