我试图从mysql数据库读取数据。在我的数据库中,我检查了数据显示为'μ'
, charset正确设置为'UTF-8'
。但是当我在PHP中运行下面的代码时,输出'μ'
显示为'?'
。我尝试了很多方法,通过添加不同类型的字符集和所有的脚本,但都是徒劳的,仍然显示为'?'
。有谁能帮我一下吗?
我的脚本如下:
<?php
ini_set("default_charset", "UTF-8");
header('Content-type: text/html; charset=UTF-8');
error_reporting(E_ALL);
ini_set("display_errors", 1);
$tender_id=$_GET['tender_id'];
include('config_sqli.php');
?>
<?php
$result=mysqli_query($con,"SELECT * FROM comparitive_st_sup WHERE
id='$member[$x]' and tender_id='$tender_id'");
while($row=mysqli_fetch_assoc($result)){
$prod_description1 = $row['prod_description'];
$prod_description = mysqli_real_escape_string($con, $prod_description1);
}
echo $prod_description;
echo '<br>';
?>
try this,
在执行实际查询之前先运行下面的查询:
mysqli_query($con, "SET NAMES 'utf8'");
或
try this your mysqli connection
$mysqli = new mysqli("localhost", "root", "", "test");
$mysqli->set_charset("utf8");
// be careful, this method can be not working (mantainers builds bugs for old php releases), first example is works fine