2

When trying to insert arabic into mysql from Perl, the arabic content is displayed in the database like أ™إ أکآ³أکآ´أ™إ but when I retrieve the value from the database it will display like ÙØ³Ø´Ù in the web page.

note that my database and table charset is utf8 and the COLLATE is utf8_general_ci.

RobEarl
  • 7,862
  • 6
  • 35
  • 50
DeyaZ
  • 63
  • 5
  • 2
    First, you need to establish what went wrong: putting it in the database, getting it from the database, or displaying it in the web page. – ikegami Nov 28 '13 at 14:03
  • Please provide the output of `local $Data::Dumper::Useqq = 1; print(Dumper($str));` before you placed it in the database and after you fetched it from the database. – ikegami Nov 28 '13 at 14:04
  • Additionally, if you have phpMyAdmin, does the text look right using it? – ikegami Nov 28 '13 at 14:05
  • Can you show us the code you use to insert and select it? – simbabque Nov 28 '13 at 17:16

2 Answers2

1

Try using SET NAMES 'UTF8' after connecting to MySQL:

my $dsn = "DBI:mysql:$base_name:$mysql_host_url";
my $dbh = DBI->connect($dsn, $user_db, $password_db) or die $DBI::errstr;
$dbh->do(qq{SET NAMES "utf8"});

As the manual says:

SET NAMES indicates what character set the client will use to send SQL statements to the server... It also specifies the character set that the server should use for sending results back to the client.

user4035
  • 22,508
  • 11
  • 59
  • 94
0

I found another solution for my question , this solution for mysql database

Change MySQL default character set to UTF-8 in my.cnf?

Community
  • 1
  • 1
DeyaZ
  • 63
  • 5