I am trying to write utf-8 rows to a MySQL table using perl / DBI. For some reason, the string is truncated at the first character other than ascii.
For example, if I set up the following table:
CREATE DATABASE testdb DEFAULT CHARSET=utf8;
CREATE TABLE testdb.testtable (textval CHAR(30)) DEFAULT CHARSET=utf8;
And then run the following perl code:
use strict;
use DBI;
my $dbh = DBI->connect('DBI:mysql:host=localhost;database=testdb', 'testuser', 'somepassword', {mysql_enable_utf8 => 1}) or die $DBI::errstr;
$dbh->do('SET NAMES utf8');
$dbh->do("INSERT INTO testtable (textval) VALUES ('the N\xFCrburgring')");
He actually writes "N". (when he should write "Nurburgring")
In the MySQL query log, I see the following:
271 Query INSERT INTO testtable (textval) VALUES ('the Nürburgring')
Thus, the row reaches the database server unchanged.
If I enter the same query directly into the MySQL console:
INSERT INTO testtable (textval) VALUES ('the Nürburgring');
The entire line is spelled correctly. Any idea what I'm doing wrong?
source
share