In drupal query I want to get two category type 'birthday and anniversary' using query.I want to get the value in array.for single category I have collected value as
$result = db_query('select response from {soap_service} where category = :category',array(':category' => 'anniversary'));
but for both (which I have tried)
$result = db_query('select response from {soap_service} where category = :category',array(':category' => 'anniversary',':category' => 'birthday'));
really to check as category = 'cele_birth' or category = 'cele_anniv'";
Basically IN condition is similar to multiple OR conditions, but You wouldn't have to rewrite column name. Also it might perform faster on some conditions than OR statement.
This should work:
db_query('select response from {soap_service} where category IN (:category)',
array(':category' => array('anniversary', 'birthday'))->fetchAll();
You can do like this,
$arr = ['anniversary','birthday'];
$result = db_query('select response from {soap_service} where category IN (:category)',array(':category' => $arr ));
As core coding standard suggest, keys in same array can not be same, it will override the values of it with new values(key value which is having index higher).
Try this:
$categories = array(anniversary,birthday);
$result = db_query('select response from {soap_service} where category IN (:categories )', array(':categories ' => $categories ));
For more information, see, especially the chapter on Placeholder arrays:
Placeholder arrays