More than three years ago I posted a similar question related to not being able to insert data into a table because of what I believe is an incorrect character set, and I'm having the same problem with the same script with different data today.
The issue is with German characters from Ilpo J�rvinen ("a" with umlaut?).
execute failed: Incorrect string value: '\xD6sterl...' with mariadb and perl DBD
DBD::mysql::st execute failed: Incorrect string value: '\xE4rvine...' for column `lsv6`.`xyz_content`.`fulltext` at row 1 at myscript.pl line 467.
I'm trying to process emails with different charsets, but apparently this one is not being encoded by my script properly. From the email:
Content-type: text/plain; charset="iso-8859-1"
Content-transfer-encoding: quoted-printable
The full script is too long to post here, but I believe these are the relevant parts where the database is involved.
sub db_connect($) {
...
return DBI->connect("DBI:mysql:database=$DB{'db'};host=$DB{'host'}", $DB{'user'}, $DB{'pass'}, { PrintError => 1, RaiseError => 1, mysql_enable_utf8mb4 => 1 } )
...
}
$fullText = $dbh->quote($fullText);
my $sql = <<EOF;
INSERT INTO xuxgc_content (title, alias, introtext, `fulltext`, state, catid, created, created_by, created_by_alias, modified, modified_by, checked_out, checked_out_time, publish_up, publish_down, images, urls, attribs, version, ordering, metakey, metadesc, metadata, access, hits, language)
VALUES ($title, "$title_alias", $introText, $fullText, $state, $catid, $created, $created_by, $created_by_alias, $modified, $modified_by, $checked_out, $checked_out_time, $publish_up, $publish_down, $images, $urls, $attribs, $version, $ordering, $metakey, $metadesc, $metadata, $access, $hits, $language);
EOF
my $sth = $dbh->prepare($sql);
$sth->execute();
db_disconnect($dbh);
If I strip out the non-ASCII characters, it works properly:
$fullText =~ s/\xE4//g;
$fullText =~ s/\xFC//g;
$fullText =~ s/\xE5//g;
Should I be using iso-8859-1 encoding instead of utf8mb4?