Executing DB::query

29 views
Skip to first unread message

ssk

unread,
May 4, 2011, 10:04:41 PM5/4/11
to Fuel Users
How can I execute a SQL query using DB::query?

This is a function in a controller:

function abc() {
$result = DB::query("SELECT * FROM table WHERE id>1");
return $result;
}

But I get:
ErrorException [ Warning ]: Invalid argument supplied for foreach()

Daniel

unread,
May 4, 2011, 11:09:51 PM5/4/11
to fue...@googlegroups.com
You should use

$result = DB::query("SELECT * FROM table WHERE id>1")->execute();

foreach($result as $item){
...
}

More info: http://fuelphp.com/docs/classes/database/usage.html

Reply all
Reply to author
Forward
0 new messages