I would do:
$result = db_select('taxonomy_index', 'ti')
->fields('ti', array('tid'))
->condition('tid', 1)
->condition('nid', 1)
->range(0, 1)
->execute()
->rowCount();
if ($result) {
drupal_set_message(t('Exists'));
}
Not your question, but you should always use placeholders to protect against SQL Injection - although if you use the query builder as described above, it will take care of it for you. In addition, you should always use the t () function when writing text to the screen.
source
share