Aman
Aman

Reputation: 2431

How to make laravel read foreign language characters from mysql database?

It is converting a readable character to "á‹á‹µ ደንበኛ". I am using "utf-8" for the columns of the table

Upvotes: 2

Views: 1538

Answers (2)

Tiago Gouvêa
Tiago Gouvêa

Reputation: 16800

You should ensure that your .env file has the following attributes:

DB_CHARSET=utf8
DB_COLLATION=utf8

It will force laravel to use this charset and collation on all queries it runs.

Upvotes: 0

hazem ali
hazem ali

Reputation: 301

First make sure as the comments said the database character is set to be utf8mb4_unicode_ci or utf8_general_ci the first charset is for the emojis anyway back to the issue .. make sure that the php files is set to be utf8 too .. by using a modern editor like phpstorm or vscode or sublime .. you might try to use tinker .. by typing php artisan tinker in your terminal window or command line if you're using widows -> then try to add a record in your database with the non-english language then check it again .. if it doesn't convert to this gibberish so the the problem is not with the database charset is with files as I said.

Upvotes: 3

Related Questions