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

Couldn't run query: Query was empty


Go to End


3 Posts   1324 Views

Avatar
DeklinKelly

Community Member, 197 Posts

8 April 2011 at 7:03am

I want to increase the value of the Counter (an integer) by one.

Here is the SQL:

UPDATE `Article` set `Counter` = `Counter` + 1 where `ID` = '12345"

But when I try to use my SQL with SQLQuery(), I get an error: "Couldn't run query: Query was empty"

$sqlQuery = new SQLQuery();
$sqlQuery->sql = "UPDATE `Article_Live` set `Counter` = `Counter` + 1 where `ID` = '". $this->ID ."'";
$sqlQuery->execute();

Avatar
swaiba

Forum Moderator, 1899 Posts

11 April 2011 at 10:18pm

how about DB::query(); instead?

Avatar
DeklinKelly

Community Member, 197 Posts

12 April 2011 at 12:21am

That works, thanks.