I'm trying to initialize eloquent with setFetchMode
as PDO::FETCH_ASSOC
.
I've tried everything possible but it doesn't work.
What I tried so far :
To add it using the addConnection
$capsule = new Illuminate\Database\Capsule\Manager;
$capsule->addConnection([
...
'fetch' => PDO::FETCH_ASSOC
]);
Using setFetchMode
$capsule->setFetchMode(PDO::FETCH_ASSOC);
Using events :
$t = new Illuminate\Events\Dispatcher;
$t->listen(Illuminate\Database\Events\StatementPrepared::class, function ($event) {
$event->statement->setFetchMode(PDO::FETCH_ASSOC);
});
But none of these work. Any idea how to make PDO::FETCH_ASSOC
work?
PS : I'm aware the first two options do not work with the recent version of eloquent, but I had to give it a try nonethless. I'm open to suggestions tho on how to make the third option work. Normally, the third one should start by looking like this Event::listen
, but I don't know where is that Events
class is coming from. Also do I need some sort of event listener?
PPS : I'm not using Laravel, I'm using illuminate's eloquent with PHP using composer.