Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

SQL query: Call to a member function execute() on a non-object


Reply

2 Posts   472 Views

Avatar
Fraser

15 October 2012 at 9:51am Community Member, 46 Posts

I am trying to execute and return results from the below statement:

$sqlQuery = new SQLQuery();
$sqlQuery->setFrom('ListingCategory_Listings');
$sqlQuery->selectField('*');
$sqlQuery->addLeftJoin('Listing', '"ListingCategory_Listings"."ListingID" = "Listing"."ID"');
$sqlQuery->addLeftJoin('SiteTree_Live', '"Listing"."ID" = "SiteTree_Live"."ID"');
$sqlQuery->addLeftJoin('ListingCategory', '"ListingCategory_Listings"."ListingCategoryID" = "ListingCategory"."ID"');
$sqlQuery->addLeftJoin('File', '"ListingCategory"."IconID" = "File"."ID"');
$rawSQL = $sqlQuery->sql();
return $rawSQL->execute();

When I output the SQL to my template and run the query through phpmyadmin, results are returned, however I am getting an error "Fatal error: Call to a member function execute() on a non-object" what am I doing wrong here?

Avatar
Fraser

15 October 2012 at 10:34am Community Member, 46 Posts

I sorted this, it was because I was trying to return the execute.