1

I have the following php code. Connection is OK but it doesn't show the Arabic text stored in the database correctly. Just question marks.

$mysqlPDO = new PDO('mysql:host='.HOSTNAME.';charset=utf8;dbname='.DBNAME.'',DBUSERNAME, DBPASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"));
$stmt =  $mysqlPDO->prepare("SHOW TABLES LIKE 'main_patches_version'");
$stmt->execute();

The DB collation is already set to utf8_general_ci and the table has utf8 as charset. This application is calling Zend libraries which I'm not aware of. I checked that the HTML has utf8 as encoding type. any suggestion? I'm using xampp server, php version 5.5.11, mysql version 5.6.16

AlShaikh
  • 43
  • 6
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – The Blue Dog Jan 17 '15 at 20:48
  • Make sure the browser uses the correct charset. Sending a header helps too `header("Content-type: text/html; charset: UTF-8");` – Charlotte Dunois Jan 17 '15 at 21:03
  • @CharlotteDunois I've added the header but no luck :( the static arabic text is displaying correctly when it's from the php code. but when it comes from the DB it didn't work. – AlShaikh Jan 18 '15 at 20:56

2 Answers2

2

I found the solution here http://akrabat.com/php/utf8-php-and-mysql/

I unmarked character_set_server=utf8 from my.ini file and it works. Thanks all

AlShaikh
  • 43
  • 6
1

Make sure your DB collation is set to use utf8_general_ci or utf8mb4_general_ci.

David Xu
  • 5,555
  • 3
  • 28
  • 50