Hello Monks.

I'm trying to insert utf8 strings on a mysql database using DBI, I think the problem is on DBI/Perl because the equivalent code worked fine on PHP on this same machine and same database.
use strict; use warnings; use DBI; binmode(STDOUT, ":utf8"); my $dbo = DBI->connect('dbi:mysql:testdb:127.0.0.1:3306','','') or die + $!; $dbo->do('SET NAMES utf8'); $dbo->{'mysql_enable_utf8'} = 1; my $str = "\x{72d0}\x{306e}\x{5de5}\x{4f5c}\x{5ba4}"; print "$str\n"; my $s = $dbo->prepare("INSERT INTO test VALUES(?);"); $s->execute($str);
As you can see, I tried some solutions I found out there already, but none of that worked. The code prints:
狐の工作室
but on the test table:
+-----------------+ | testcol | +-----------------+ | ????? | +-----------------+
the mysql server version is 5.1.41, DBI is 1.615 and perl is 5.12.1
I am out of ideas already..what could be the problem ?

In reply to Inserting UTF-8 on Mysql using DBI by Fox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.