views:

99

answers:

3

Hello, I'm re-designing a Web site and I have a problem with the existing data base: The database collate is set to utf8_unicode_ci and in the table row I'm calling the collate seems to be set to latin1_swedish_ci the characters store in it are Japanese (but even in phpmyadmin) you see other characters (I guess because of the latin1_swedish_ci).

When I print the result from the query I get a bunch of ??? now using

    mysql_query('SET NAMES utf8');
 mysql_set_charset('utf8',$conn); 

Will output 2009â€N10ŒŽÂ†2009?N10???2009â€N11ŒŽÂ†2009?N11???

Any ideas?

+1  A: 

Because the table was set to use latin1_swedish_ci, it was unable to correctly store the UTF-8 data that was entered. You need to switch that table to use utf8_unicode_ci for data going forward, but any existing data is essentially corrupted. You would have to re-enter the data after switching the collate to get the correct Japanese characters for the existing records.

iKnowKungFoo
Thanks iKnowKungFoo, but the thing is that the current database as it was build is being used by another version of the site that they will maintain operative. So I can't really do this and re-enter the info.
Dario Novoa
A: 

You need to change the charset to utf8. The collation do not need to be changed to display japanese characters (but to be able to sort and compare texts it might be a good idea to change it to utf8_general_ci).

Muleskinner
Thanks Muleskinner, the DB Character set is set to UTF8 -> utf8_general_ci) but the field has the latin1... collation so that was an issue. I'll post the solution I implemented in a minute.
Dario Novoa
A: 

Hi all thanks for your reply's this is what happened, I couldn't really change anything in the DB since there's another version of the site that still uses that DB and will be up. So the solution I found was the following:

Case scenario: The DB is set to use UTF8 -> (utf8_general_ci) but the field (at least the one's I needed where set to latin1_swedish_ci.

Solution: After mysql_connect I put the following:

mysql_query("SET NAMES 'Shift_JIS'",$conn);
mysql_set_charset('Shift_JIS',$conn); 

Then in the PHP file:

$titleJP = $row['titleJP'];
$titleJP = mb_convert_encoding($titleJP, "UTF-8", mb_detect_encoding($titleJP,"Shift_JIS,JIS,SJIS,eucjp-win"));

Now that worked perfectly the characters are displayed in correct Japanese. I tried every other solution I could think of with no luck (utf-8_decode/encode php functions, etc.. etc..)

Dario Novoa