?
Solved

drupal basic sql query

Posted on 2012-12-22
4
Medium Priority
?
284 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 2000 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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