2

I am trying to convert database column that is stored in utf8_unicode_ci collation to hindi characters.

For example: दà¥à¤ƒà¤– का अधिकार- Quiz 1

This is not showing in hindi language, I even added <meta charset="utf-8"> after <head> tag. But still it displays the same.

In my previous website it was working fine, but when I imported data to my new website the characters are not being displayed as expected.

Then after some research, I found out some PHP functions as below

   echo iconv('UTF-8', 'ISO-8859-1', $utf8);
   echo "<br>";
   echo mb_convert_encoding($utf8, 'ISO-8859-1', 'UTF-8');
   echo "<br>";

iconv displayed Error iconv(): Detected an illegal character in input string and mb_convert_encoding outputs ?? ? ??- Quiz 1

The expected results for the above string is = दुःख का अधिकार- Quiz 1

ANSWER

After all the help I got the solution, I changed old database charset to UTF-8 using this

UPDATE quiz_question SET question_desc = CONVERT( CONVERT( CONVERT( question_desc USING latin1 ) USING BINARY ) USING UTF8 )

topper1309
  • 151
  • 3
  • 16
  • All it takes, is one wrong charset setting in your application - *everything* needs to be the same charset! I have previously written [**an answer about UTF-8 encoding**](https://stackoverflow.com/a/31899827/4535200) that contains a little checklist, that will cover *most* of the charset issues in a PHP/MySQL application. There's also a more in-depth topic, [**UTF-8 All the Way Through**](https://stackoverflow.com/q/279170/4535200). Most likely, you'll find a solution in either one or both of these topics. – Qirel Apr 07 '19 at 09:19
  • Thank you for replying, I will go through them and will let you know accordingly – topper1309 Apr 07 '19 at 09:23
  • @Qirel actually my old database was in latin1_swedish_ci and in my new database it is utf8_unicode_ci. Is this a problem ? – topper1309 Apr 07 '19 at 09:29
  • The actual charset is more important than the collation. There's a difference between collation and charset - but both should be set to UTF8. Set the character encoding of all aspects of your application to UTF8, and you won't have any issues. Data already stored incorrectly will not be fixed though, and will have to be updated or re-inserted. – Qirel Apr 07 '19 at 09:43
  • @Qirel The charset determines the possible collations, so a latin1 collation implies a latin1 charset. Since latin1 cannot encode Hindi at all, that hints at the data in the database already being garbage. Topper, look at the second duplicate. – deceze Apr 07 '19 at 10:15
  • @deceze Ok, I also tried creating a new table with same latin1 collation in my new database. But still didn't get results. I will go through the duplicate post and will let you know – topper1309 Apr 07 '19 at 10:32

0 Answers0