Error when trying to extend a db_select query I'm trying to add a field to my query by using addField(). However, whenever I add this to the query I get a whitescreen and an apache error message on the line after. Any help in resolving this would be much appreciated.

Apache error log:

PHP Fatal error: Call to a member function extend() on a non-object

db_select query:

$query = db_select('z_revision', 't')
    -&gt;fields('t', array('drupal_user_id'))
    -&gt;addField('t', 'z', 'category')
    -&gt;extend('PagerDefault') # error on this line
    -&gt;extend('TableSort')-&gt;orderByHeader($header)
    -&gt;limit(30)
    -&gt;execute();


Ideally this would give me a two column table with headers 'drupal_user_id' and 'category' - all the rows in the category column having 'z' as a value.
addField returns the alias of the field that's added, not the query object. You just need to break your code up a bit:

$query = db_select('z_revision', 't')
  -&gt;fields('t', array('drupal_user_id'));

$query-&gt;addField('t', 'z', 'category');

$result = $query-&gt;extend('PagerDefault')
  -&gt;extend('TableSort')
  -&gt;orderByHeader($header)
  -&gt;limit(30)
  -&gt;execute();