Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter base PDO configuration in Laravel

My shared web host have some problems with query prepares and I want to enable PDO's emulated prepares, there's no option for this in the config\database.php.

Is there any way I can do that in Laravel?

like image 343
Positivity Avatar asked Mar 13 '23 02:03

Positivity


1 Answers

You can add an "options" array to add options to your Database Connection within config/database.php:

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
        // Additional options here
        'options'   => [PDO::ATTR_EMULATE_PREPARES => true, PDO::MYSQL_ATTR_COMPRESS => true,]
    ],

You will see I've also switched on MYSQL_ATTR_COMPRESS for my connection.

You can find more information on some of the options they have built in here:

https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Connectors/Connector.php

like image 74
Justin Origin Broadband Avatar answered Mar 16 '23 04:03

Justin Origin Broadband