I missed this statement and I ended up with funny characters in the database:
mysql_enable_utf8 flag documentation
Additionally, turning on this flag tells MySQL that incoming data should be treated as UTF-8. This will only take effect if used as part of the call to connect(). If you turn the flag on after connecting, you will need to issue the command SET NAMES utf8 to get the same effect.
This is a part of the code:
use strict;
use utf8;
use open qw/:std :utf8/;
use DBI;
my $dbh = DBI->connect("...", $user, $pass) or die_report($@);
my $query;
$dbh->{'mysql_enable_utf8'} = 1; #this caused the problem, because it was added after the connect() statement.
$dbh->prepare("CREATE TABLE `$database`.`$table` (`id` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT `response` MEDIUMTEXT) ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci")->execute or die($@);
my $ua = LWP::UserAgent->new;
$response = $ua->get('http://example.com')->decoded_content;
$query = $dbh->prepare("INSERT INTO `$mysql_database`.`$mysql_table` (`id`, `response`) VALUES (?, ?)");
$query->execute($id, $response);
I need to understand what happens to $response
when it is inserted in mysql and how to revert the damage.
Does it get double encoded? Can I fix it in a smart way?