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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

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


Go to End


2 Posts   1538 Views

Avatar
Fraser

Community Member, 48 Posts

15 October 2012 at 9:51am

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

Community Member, 48 Posts

15 October 2012 at 10:34am

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