in reply to Re^4: UTF-8 problem, some chars appear as \x..
in thread UTF-8 problem, some chars appear as \x..

AFAIK, MySQL returns correct UTF-8 data but doesn't set UTF-8 flag. What are other options to fix this?

Don't pass a string of char where a string of bytes is expected.

my $octets_for_mysql = decode('UTF-8', $chars); # Option 1 my $octets_for_mysql = encode('utf8', $chars); # Option 2

As for retrieving the data,

my $chars = decode('UTF-8', $octets_from_mysql); # Option 1 my $chars = decode('utf8', $octets_from_mysql); # Option 2

The difference between options 1 and 2 is explained in "UTF-8 vs. utf8" in Encode's docs.

Replies are listed 'Best First'.
Re^6: UTF-8 problem, some chars appear as \x..
by zanzibar (Novice) on Feb 20, 2007 at 10:06 UTC

    Is it possible to decode the data on a lower level? I mean somewhere between DBI and Class-DBI so that Class-DBI accessors provide already decoded data.

    In the code I have posted above I have changed Encode::_utf8_on($_) to $_ = Encode::decode_utf8($_) unless Encode::is_utf8($_) but I get Cannot decode string with wide characters at ..../Encode.pm line 162