Daniel Daniel - 21 days ago 7
PHP Question

PHP - How to use strtolower in query

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

Using PDO and assuming MySQL

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