Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: I'm having a lot of trouble getting UTF-8 output via Perl/DBI on OS X

by Cody Fendant (Pilgrim)
on Sep 22, 2012 at 08:07 UTC ( #995077=note: print w/ replies, xml ) Need Help??


in reply to Re: I'm having a lot of trouble getting UTF-8 output via Perl/DBI on OS X
in thread I'm having a lot of trouble getting UTF-8 output via Perl/DBI on OS X

$dbh->do("SET NAMES 'utf8'");

That works! Thank you!

So, what's going on? It's actually MySQL auto-converting from UTF-8 when I never asked it to?


Comment on Re^2: I'm having a lot of trouble getting UTF-8 output via Perl/DBI on OS X
Download Code
Re^3: I'm having a lot of trouble getting UTF-8 output via Perl/DBI on OS X
by roboticus (Canon) on Sep 22, 2012 at 12:26 UTC

    Cody Fendant:

    I just looked at the DBD::mysql documentation, and there's a setting mysql_enable_utf8 that defaults to off. I've not used DBD::mysql, but based on the docs, it looks like you can just add the setting in the connect statement like this:

    $dbh= DBI->connect("DBI:mysql:test;mysql_enable_utf8=1", "root", "");

    ++ for the OP: clear, detailed and didn't seem to miss any pertinent information.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: I'm having a lot of trouble getting UTF-8 output via Perl/DBI on OS X
by remiah (Hermit) on Sep 23, 2012 at 03:06 UTC

    Hello, Cody Fendant,roboticus.

    PostgreSQL or MySQL seems to have encoding for server storage, and for client encoding. So, I guess 'select hex(field) from table' shows bytes for server storage and when you receive the value at the client, it is converted to encoding of client.

    "mysql_enable_utf8=1" and "SET NAMES 'utf8'" sets encoding for client. I saw both of them gives me good result with DBD::mysql version "4.008".

    In fact, I am not the man of MySQL... Please point me if I say wrong.

    P.S: With my DBD::mysql version, the result is utf-8 bytes, not Perl's character. utf8::is_utf8 will tell you whether it is decoded character or bytes.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995077]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-08-23 16:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (174 votes), past polls