Friday, March 10, 2017

Changing PDO to FETCH_ASSOC when using eloquent outside laravel

I would like to set PDO to FETCH_ASSOC by default. I'm using eloquent outside laravel, and here is the boot up code:

class DbSql
{

    /**
     * Use the eloquent query builder and orm. Bypass PDO interface.
     * @return Capsule
     */
    public function db()
    {
        $capsule = new Capsule;

        $capsule->addConnection( [
            'driver'    => Settings::DATABASE_DRIVER,
            'host'      => Settings::DATABASE_HOST,
            'database'  => Settings::DATABASE_NAME,
            'username'  => Settings::DATABASE_USERNAME,
            'password'  => Settings::DATABASE_PASSWORD,
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ] );

        # Make this Capsule instance available globally via static methods... (optional)
        $capsule->setAsGlobal();


        return $capsule;
    }
}

Anyway to modify this code to achieve the desired result ?



via Robert Brax

Advertisement