Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sebastien_59's avatar

DB::setFetchMode(PDO::FETCH_ASSOC) in Laravel 5.3

Hi !

I have problem with DB:: setFetchMode() on Laravel 5.3. I want to extract the data from my database in an associative array, but this line seems to do nothing... I remember it was working on 5.2.

Do you have any information or an idea of why it doesn't work ? I have a solution without this function but it's not as good as this.

Here is my model :

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use PDO;

class Client extends Model
{

    protected $fillable = [
        'idClient', 'nom', 'description', 'idType',
    ];

    public function getAll(){
        DB::setFetchMode(PDO::FETCH_ASSOC);
        return  DB::table("clients")->join('clientType', 'clientType.idType', '=', 'clients.idType')->get();
    }

    public function getById($idClient){
        DB::setFetchMode(PDO::FETCH_ASSOC);
        return DB::table("clients")->join('clientType', 'clientType.idType', '=', 'clients.idType')->where('clients.idClient', $idClient)->get();
    }
}?>

Thank you !

0 likes
2 replies

Please or to participate in this conversation.