Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Perl DBI can't display Chinese text?

by graff (Chancellor)
on Oct 13, 2013 at 21:45 UTC ( #1058105=note: print w/replies, xml ) Need Help??

in reply to Perl DBI can't display Chinese text?

Do you have some method other than Perl for inspecting the contents of the database? It's important to know for sure that the database contains "correct" data in the first place.

If that's true, the next thing is to make sure what character encoding is being used by the database server to store (or return) the data.

If the database stores/returns data in UTF-8 encoding, the next thing is to do just one of the following (whichever one is easiest or makes the most sense):

1. Figure out how to configure your perl DBI connection to the database, so that perl will know that it's getting UTF-8 data in response to queries. OR

2. Connect using the "easiest" (default) method, and use Encode; process each string you get from a query like this:

my $usable_string = decode( 'utf8', $string_from_database );
The latter approach would also work if you find out that the database server returns strings using some other encoding (e.g. "gb2312" or whatever) - just use that other encoding in place of "utf8" in the decode() call, and that will turn the database string into perl-internal (usable) utf8.

If you have trouble, you'll need to show us (1) an example of data you expect to get back (because you've seen this data using some other tool to query the database), (2) the perl code you used to try getting the string, and (3) what you actually got from your perl script.

As indicated in a previous reply above, it may also be important to ensure that you are using a terminal or other display method that you are sure is able to "do the right thing" with the text in question.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058105]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2018-02-23 05:38 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (300 votes). Check out past polls.