Solved

drupal basic sql query

Posted on 2012-12-22
4
283 Views
Last Modified: 2012-12-27
Hi, Please could someone help

This is my call:

  
function zendcalender_data() {
  $query = db_select('node', 'n')
      ->fields('n', array('nid', 'title', 'created'))
      ->leftJoin('field_data_field_event_date', 'fed', "(fed.entity_id = n.nid AND fed.entity_type = node AND fed.deleted = 0)")
      ->condition('status', 1)
      ->orderBy('created', 'DESC'); 
  $query->execute();


  return $query;
}

Open in new window


In drush I'm just running a simple php script with print_r using the php-script command on the returned data and I'm getting this error.
...
Drush command terminated abnormally due to an unrecoverable error.                                             Error: Call to a member function condition() on a non-object in... line (the one with orderBy above)

Whats going on?

Thanks  Darren
0
Comment
Question by:darren-w-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Leon Teale
ID: 38716172
you might need this patch:

http://drupal.org/node/1719370
0
 
LVL 13

Author Comment

by:darren-w-
ID: 38716195
Dont think this is it, running  7.17 that was only updated a few weeks back
0
 
LVL 12

Accepted Solution

by:
sivagnanam chandrakanth earned 500 total points
ID: 38718040
your function has to be like this

function zendcalender_data() {
  $query = db_select('node', 'n');
      $query->fields('n', array('nid', 'title', 'created'));
      $query->leftJoin('field_data_field_event_date', 'fed', "(fed.entity_id = n.nid AND fed.entity_type = node AND fed.deleted = 0)");
      $query->condition('status', 1)
      ->orderBy('created', 'DESC');
  $query->execute();


  return $query;
}
Whenever you use join in D7, you have the split the query like this..
0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 38724175
needed to add fetchAll() to call to get results
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question