Reputation: 363
I am trying to encode the '£' and inserted into DB it is storing as '£',while fetching it is displaying as £, I am decoded this data , but eventhough it is displaying as £.Using perl script , Here is my code.
#!/usr/local/perl-5.20.1/bin/perl
use HTML::Entities;
$str="£";
$str=HTML::Entities::encode($str);
my $sth = $dbh->prepare("INSERT INTO notes VALUES (null,'FD',?,?)");
$sth->execute('1','2',time(),$str);
$sth = $dbh->execute("SELECT content FROM notes WHERE requestID = 1);
while (my @temp = $sth->fetchrow_array()) {
$note = HTML::Entities::decode($temp[0]);
}
In terminal it is displaying as £ after decoding of fetched DB data (£)
Upvotes: 0
Views: 238
Reputation: 2935
If you have characters outside the ascii-range inside your perl-script you have to use utf8
and ensure that your script is stored in the utf-8 encoding (it is).
The main purpose nowadays for use utf8
is to tell perl that your script is stored in utf8. If you want to use it for something else, read perldoc perlunicode
first, probably you'll need some other pragma or module.
Also you didn't state what your database driver is. Probably your database is capable of either storing the value as binary data, you can then decode it with Encode::decode
, or your driver is capable of storing utf-8 text, then you could use that.
Upvotes: 1