phrants.net
4Fév/210

GODDAMN UTF-8 / PHP

About 25 hours spent in two days on figuring out this problem with my PHP myAdmin app. Let's break it down. A shared hosting plan eliminated support for earlier versions of PHP. I thought I was ready for this, having carefully updated all the old mySQL calls, functions, etc. What I had not counted on was the default_charset change in 5.6 and beyond. It was previously Latin1 and then it went to UTF-8 (which is the right direction, of course). BUT, my database was full of double-encoded records spanning over a decade. I tried all the tricks I could find, frantically dumping and importing, and trying to convert the affected tables. Internet sleuthing reveals that UTF-8 encoding problems have clearly infuriated many developers. But, I did manage to create a quick fix...

Problem: mySQL database double encoded everything

Long term solution: Fix double encoded strings in database


Quick solution: explicitly revert to the OLD encoding that was in place prior to change in 5.6


Now, fixing the database is going to take some time. I had no luck with quick conversions, dumps, imports, etc. But, I was able to restore normal functionality to the app with a relatively small change:

 mysqli_query($my_connection,"SET CHARACTER SET 'Latin1'");


This is placed right after the connection to the database is made. Results? The garbled data became ungarbled for display. Of course, I had to include this line for every call to the database, which involved updating 20+ files. But it was the quick fix I needed in the moment.

Commentaires (0) Trackbacks (0)

Aucun commentaire pour l'instant


Laisser un commentaire


Aucun trackbacks pour l'instant