1

This question already has an answer here:

I want the query like below:

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

My current query is:

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

But it doesn't work.

How should I write this type of query?

marked as duplicate by Yusef Mohamadi, Pierre.Vriens 7 Oct 4 '16 at 10:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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
3

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.