I have SQL functions stored on my database.
However, I can not call them.
$nb = DB::select('SELECT nb_seances_archivees()');
The result is :
array:1 [▼
0 => {#186 ▼
+"nb_seances_archivees": 0
}
]
But the desired result is just 0
.
Thank's for help !
By default DB::select
return an array of objects, you can use collections to get the first result:
$nb = collect(DB::select('SELECT nb_seances_archivees() AS nb'))->first()->nb;
Or directly access the first object in the array:
$nb = DB::select('SELECT nb_seances_archivees() AS nb')[0]->nb;
If you want to pass parameters then you should do:
DB::select('SELECT nb_seances_archivees(?) AS nb', [$parameter]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With