0
4

2 回答 2

2

you may need to add this to the connection:

my $dbh = DBI->connect(...);
$dbh->do("SET NAMES 'utf8'");  #<-- add this after the connection was established

With SET NAMES 'utf8' we are doing in one sentence:

SET character_set_client = 'UTF8';
SET character_set_results = 'UTF8';
SET character_set_connection = 'UTF8';

MySQL documentation may be helpful.

于 2013-08-07T07:01:17.307 回答
1

If you use the mysql_enable_utf8 attribute when connecting to the database, then DBD::mysql will do the conversion for you.

my $dbh = DBI->connect("dbi:mysql:database=$db", $user, $pass",
                       { mysql_enable_utf8 => 1 });
于 2013-08-07T10:08:56.993 回答