Nandakumar
Nandakumar

Reputation: 1101

Laravel: default to charset and collation of existing Database?

In Laravel, Everytime, while running the website,

"set names 'utf8' collate 'utf8_unicode_ci'"

is executing.

How can I avoid this ? Instead of doing this in the code. We have configured in the database itself. How can I remove charset and collation in database configuration ?

> config/database.php
> 
> 'database' => [
>     'driver'    => 'mysql',
>     'host'      => env('DB_HOST', 'localhost'),
>     'port'      => env('DB_PORT'),
>     'database'  => env('DATABASE'),
>     'username'  => env('DB_USERNAME', 'forge'),
>     'password'  => env('DB_PASSWORD', ''),
>     'charset'   => 'utf8', // Need to remove or make ''
>     'collation' => 'utf8_unicode_ci', // Need to remove or make ''
>     'prefix'    => env('DB_PREFIX', ''),
>     'strict'    => false, ],

Upvotes: 5

Views: 32666

Answers (2)

Soul's tear Go
Soul's tear Go

Reputation: 41

You can just remove 'charset' and 'collation' from mysql connection array and run php artisan config:clear after that.

Upvotes: 3

darthsoup
darthsoup

Reputation: 436

Not directly sure what you try to achieve with this. But it is not possible without changing the MySQL Classes.

Take a look at the Illuminate/Database/Connectors/MySqlConnector Class.

Upvotes: -1

Related Questions