Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: goofy2feet - lokakuu 04, 2007, 08:56:13 AP

Otsikko: japanese chrs garbled by MySQL
Kirjoitti: goofy2feet - lokakuu 04, 2007, 08:56:13 AP
I'm sending japanese characters in one field of one table of a MySQL database.
I use addslashes() and htmlspecialchars() on the variable, and the collation of the whole database is Shift_JIS (the most common encoding in Japan, and the one that my application is set to on every page.
But, when I pull the data out of the table and display it, it is just garbled nonsense - ie., I am losing the Japanese when I put it into the database. I know it is garbled as soon as it goes in as I have checked using phpMyAdmin.

Does anyone know a way I can at least get the japanese characters converted to numerical entities to be saved like that?

Some may suggest using UTF-8, but I don't know how to get my japanese OS to let me input japanese using that encoding - I think I am stuck with Shift-JIS.

I really hope someone can give an amateur like me some pointers or help with this problem.
Otsikko: Re: japanese chrs garbled by MySQL
Kirjoitti: karlbenson - lokakuu 04, 2007, 03:41:51 IP
when you use htmlspecialchars() are your setting the encoding version?

htmlspecialchars($string,"utf-8");

See http://uk2.php.net/htmlspecialchars
Otsikko: Re: japanese chrs garbled by MySQL
Kirjoitti: goofy2feet - lokakuu 05, 2007, 08:02:46 IP
I wasn't setting the encoding version, no.
I tried that, as you suggested it, but when I specify "shift-jis" I get an error message that the parameter is expected to be 'long, string', whatever that is supposed to mean.

I also tried with htmlentities(), but my Japanese is still getting garbled.

Does anyone have any more ideas?
Otsikko: Re: japanese chrs garbled by MySQL
Kirjoitti: goofy2feet - lokakuu 05, 2007, 08:26:29 IP
Worked it out... needed to use html_entity_decode() to get the Japanese characters back again.
Otsikko: Re: japanese chrs garbled by MySQL
Kirjoitti: K0H_K1u - lokakuu 06, 2007, 11:09:58 AP
Out of curiosity... this is 5.* ver of Mysql you are using goofy2feet? Correct?
Otsikko: Re: japanese chrs garbled by MySQL
Kirjoitti: goofy2feet - lokakuu 06, 2007, 08:57:38 IP
No, actually, my server provider has MySQL version 4.1.20-standard as I discovered when I tried using a string function from the php documentation for version 5 and got an 'unrecognized function' error.

Should this make me think they're not really on top of their game?