I want the query like below:

select * from tbl where LOWER(name) = $name

My current query is:

$resultArr = db_select('adbanner', 'n')
    ->condition(LOWER('n.blog_title'), $page, '=')

But it doesn't work.

How should I write this type of query?

  • There seems to be a typo with the quotes in your condition. Did you mean the following? $resultArr = db_select('adbanner', 'n') ->fields('n') ->condition('LOWER(n.blog_title)', $page, '=') ->execute() ->fetchAll(); – dinopmi Oct 4 '16 at 7:18

You can use LIKE instated of LOWER.

OR write something

$query->where('LOWER(n.blog_title) = :page', array(':page' => $page));

Refer Using SQL functions in conditionals in Drupal 7 db_select()

  • 1
    I believe LIKE is much heavier than LOWER, so the code you showed is preferable. – Jaypan Oct 4 '16 at 8:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.