Solved

drupal basic sql query

Posted on 2012-12-22
4
272 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-
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now