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
Solved

drupal basic sql query

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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 …
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 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