0

I have a Mysql database with all tables collated as 'utf8_unicode_ci'. Also all data I wrote to the Database with php was encoded in utf8. But I forgot to set the mysql connection encoding to utf8, so it probably defaulted to ISO-8859.

For a long time this was not a problem. Although special characters where displayed wrong in Tools like phpMyAdmin, the data was correct when loading it into my php application, as long as I kept using the wrong connection encoding.

But now I need to use my database from another application, that (correctly) does not use ISO-8859 as connection encoding and gets broken special characters.

Now I want to convert my database so I can use the right connection encoding.

I already tried this: mysql wrong connection encoding

But I does not help for me. The closest I got to a solution was 'ut8_decode(utf8_decode($data))'. But this breaks fields that start with a special character.

Additional Information:

So what might happen is the following:

  1. My application sends some utf8 Data to the database.

  2. Mysql gets the data but thinks (due to the connection encoding) that it is not utf8, and converts it, to fit for the 'utf8_unicode_ci' collation.

  3. When my php application reads the data from the database mysql seems to undo the previous conversion so everything looks fine again from my php app.

3
  • I have never done this but I think this could work: create some basic script with two connections to the very same database. The first connection will only read the data without setting the connection encoding. You will go table by table by one step, read the data with the first connection to some array, truncate table and write the data back with the second connection that has proper connection encoding set. Kinda hard coded but should work... Commented Jan 22, 2013 at 10:35
  • I think it would work, but my database is big, and it would take long to convert it this way. Commented Jan 22, 2013 at 11:32
  • Yep, I was affraid You could say something like that... Then maybe somebody else could suggest something more applicable... Good luck! Commented Jan 22, 2013 at 12:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.