0

I'm fixing up a module and I have the following db_select() code, but I'm getting the following error:

Fatal error: Call to a member function execute() on a non-object in /var/www/xxx/sites/all/modules/xxx/xxx.module on line 414

I think it has something to do with the addExpression line, but I'm unsure of what this line does or what is the equivalent of addExpression in sql? What is MAX(poss), poss -- mean?

$query_poss = db_select('saved_lists', 'saved_lists')
  ->condition('saved_lists.lid', $lid)
  ->addExpression('MAX(poss)', 'poss')
  ->execute()
  ->fetchField();
2

The addExpression method returns the unique alias that was assigned for this expression, and thus cannot be chained.

Please look at this example and the document.

$q = db_select('parser_subtasks', 'st')
 ->condition('QueueID', $task['ID'])
 ->condition('IsDone', 0);
$q->addExpression('MIN(Delay)');
$min_time = $q->execute()->fetchField();
  • what is the equivalent of that in sql? im not sure what "unique alias" and expression mean when u mention it. MIN and MAX is meaning the highest or lowest of the returned results? sorry but its a bit confusing for me. – Patoshi パトシ Nov 5 '15 at 5:02
  • your right i had to make it into a separate line. why is that? i understand max() now. – Patoshi パトシ Nov 5 '15 at 5:55
  • @duckx The addExpression returns the alias you specified or a string like 'expression_2'. So that is not an object and don't have execute method. The condition method can be chained because it returns the query object itself. – leetom Nov 5 '15 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.