0

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?

1
  • Make sure you use the top db_select syntax instead of direct query statement to avoid SQL Injection attacks.. It temping given how complicated the db_select syntax can be when joining tables. Commented Aug 20, 2013 at 6:50

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.