开发者

Reading UTF-8 data from MySQL shows ? instead of ı

Here is how I read the data:

<?php
$id = $_GET["id"];
$number = mysql_real_escape_string($id);
$result = mysql_query('SELECT * FROM `mystory` where `id` = ' . "$number" .开发者_开发技巧 ' LIMIT 1');

$row = mysql_fetch_assoc($result);
echo $row['story'];
?>

The data is encoded as utf8_bin. Insted of ı PHP outputs ?

Why is that?


You need to make sure that your connection to the database us in UTF-8 as well. You can do that this way:

mysql_query("SET NAMES utf8");

Also make sure that you are telling the browser that it is UTF-8:

header("Content-type: text/html; charset=utf-8");


This is the only code worked for me :-

mysqli_set_charset($con,'utf8');

Where $con is your connection value to DB . Be sure put the code after connect and error code and you will be fine .


I am use all this operations:

mysql_query ('SET NAMES utf8');
mysql_query ('SET CHARACTER utf8');
mysql_set_charset ('utf8', $LINK);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜