Alexander  Maximiuk
Alexander Maximiuk

Reputation: 74

Query in database with join in drupal

This code not working

$var = db_select('taxonomy_term_data', 'tt')
  ->fields('tt', array('name'))
  ->join('my_table', 'dd', 'tt.tid = dd.my_field')
  ->execute()

But next code working normally.

$var = db_query('SELECT name FROM taxonomy_term_data tt JOIN my_table dd ON tt.tid = dd.my_field')

where went my wrong?

Upvotes: 0

Views: 150

Answers (1)

Clive
Clive

Reputation: 36956

join() isn't chain-able, use

$query = db_select('taxonomy_term_data', 'tt')->fields('tt', array('name'));
$query->join('my_table', 'dd', 'tt.tid = dd.my_field');
$var = $query->execute()

Upvotes: 2

Related Questions