Converting MySQL data - charset problems

Hi there,

I’m currently trying to convert some data stored in a MySQL-db.
It’s a PunBB forum, tables are UTF-8, and should be converted to PHPBB2 (Latin1 tables).
My problem is - equally which charsets and functions I use for the conversion (within my PHP script) - special chars (e.g. German umlauts) won’t show (respectively garbled).

So, here’s my current procedure:
-> SET NAMES utf8
-> Select data from UTF8 table
-> SET NAMES latin1
-> Insert data into latin1 table

I’ve also tried to convert the data before inserting it using:
-> utf8_decode(<string>)
-> utf8_decode(utf8_decode(<string>)) (yes, doubled, just for testing)
-> mb_convert_encoding(<string>, iso-8859-1)
-> mb_convert_encoding(<string>, iso-8859-1, utf-8)

I’va also tested with:
-> No SET NAMES at all (should be UTF-8 as this is my default)
-> SET NAMES utf8 without changig before inserting
-> SET NAMES latin1 before selecting

Any ideas what’s wrong with my approach?
I’m running out of ideas and need to get that fixed.

If you need further input (e.g. table structures) let me know but please be patient, gotta get some sleep as it’s already 5 am.

Thanks in advance!

mb_convert_encoding should really work, perhaps try htmlspecial chars with one charset then entity_decode with another?

Clasping at straws…

Ahh, wrong account!

Ah, damnit…
I think I found the problem now.
The PHPBB forum didn’t use “SET NAMES latin1”, it didn’t set any special charset for the connection.
After adding this (directly after it connects to the db) it seems to work.

The funny thing is - I’ve got several thousands (yes, thousands) PHPBBs running with exactly these file versions I’m using to test the conversion and they all work without SET NAMES.
The only difference is, that they are not converted from a UTF-8 PunBB but were created directly as PHPBBs from within one of my scripts.

Should’ve thought of that…was really too late yesterday :slight_smile:

Oh, btw, I’m now using mb_convert(<string>, ISO-8859-1, UTF-8) to convert the data.

Thanks to all that took a minute to think about the problem!