开发者

Insert swedish characters to opencart tables

I just created a script to import a given file (csv) to ope开发者_StackOverflowncart. The remote server transmits the data as iso-8859-1 and opencart uses utf8_bin collaction as default.

My problem is, that the script, where default echo statements show the desired output without problems or weird characters, doesn't submits the data to the database without messing up the special swedish characters.

Am example would be the word: Värmepump This definately shouldn't look like that.

Any idea what exactly could fail? I already tried to add the SET NAMES 'utf8' query but it didn't help.


Well, if the data is utf8 encoded, my guess would be there's some issue either in the database or in the database connection. Here's a few debugging tips for you.

MySQL database and table character sets/collations (from command line)

mysql -u [youruser] [yourdatabase] -p
mysql> SHOW CREATE DATABASE [yourdatabase];
mysql> SHOW CREATE TABLE [yourtable];

Everything should be utf8.

MySQL database connection (from PHP script)

$result = mysql_query("SHOW VARIABLES LIKE '%character%'");

while ($row = mysql_fetch_assoc($result))
{
    error_log(print_r($row, true));
}

Everything should be utf8 here as well.

EDIT: Your string is in fact encoded twice. Running a simple

echo utf8_decode(utf8_decode('Värmepump'))."\n";

in an ANSI-encoded PHP file outputs the expected "Värmepump". Make sure you encode your data only once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜