Arabic language in php/mysql appears “????” question marks in html [duplicate]

帅比萌擦擦* 提交于 2019-11-27 13:45:16

问题


Possible Duplicate:
Save Data in Arabic in MySQL database

I have a problem with retrieving Arabic data from MYSQL database using PHP, it appears as question marks "????" in HTML:

  1. I have a database with "utf8_general_ci" as collation.
  2. The database contains some data in Arabic Language.
  3. The HTML encoding is "UTF-8".
  4. When I tried to retrieve the data in HTML, it appears as "?????".

Please Help !!!


回答1:


you must set charset in first connect with mysql by this query:

SET CHARACTER SET utf8

for example in mysqli functions

$MySQL_Handle = mysqli_connect(HOSTNAME,DATABASE_USERNAME,DATABASE_PASSWORD,DATABASE_NAME) 
or die ( mysqli_error($MySQL_Handle) ); 

$sSQL= 'SET CHARACTER SET utf8'; 

mysqli_query($MySQL_Handle,$sSQL) 
or die ('Can\'t charset in DataBase'); 

and PDO sample :

$dbh = new PDO('mysql:host=localhost;dbname=' . $DB_NAME, $DB_USER,
$DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
$dbh->exec("SET CHARACTER SET UTF8");

this action need before insert and before select.



来源:https://stackoverflow.com/questions/13439324/arabic-language-in-php-mysql-appears-question-marks-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!