Reputation: 666
Hi i am new to Laravel and just trying to get some data out of a table in my database. I did it the same way as in the doc's but the array i get returned is always empty. It seems to connect fine and it done return an array but with nothing in it.
In my controller
public function run()
{
$results = DB::select('select * from product', array(1));
return sizeof($results);
}
All i get back is 0 and yes there is data in my database if i run the same query in phpMyAdmin i get 4 result back. Any one got any ideas on why this dose not work?
Thanks.
Upvotes: 0
Views: 4560
Reputation: 87719
This one should work:
public function run()
{
$results = DB::table('product')->get();
return count($results);
}
Also, take a look at the queries section of Laravel docs: http://laravel.com/docs/queries
If you need to execute a raw query, it should be done this way:
$results = DB::select(DB::raw('select * from product'))->get();
Upvotes: 1