laradev
laradev

Reputation: 918

Character encoding issue in mysql

In my database, I have some content like this

അവരുടെ മനസ്സുകളില്‍.

But, when i am trying to fetch the content using PHP and display it in broswer, it is showing only some question marks like ????????? ???????. ??????.

I tried to set the content type header like this

header('Content-Type: text/html; charset=utf-8');

But it doesnt work.

How can i solve this ? any help would be greatly appreciated.

Upvotes: 1

Views: 51

Answers (2)

juco
juco

Reputation: 6342

Depending on the method you are using to connect to the DB, you should be specifying the charset.

With PDO, you can specify the charset in PDO::__construct(), such as: charset=UTF-8

Otherwise you have mysqli::set_charset() for MySQLi, or god forbid you're still using mysql_* functions there's mysql_set_charset()

Upvotes: 1

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

It does not work because you got this broken during data fetch and you are setting display encoding - it's already too late. Simply ensure correct encoding during connection by using either using proper method like mysqli_set_charset() or do query SET NAMES UTF8 just after your connect to DB

Upvotes: 2

Related Questions