我试图从mysql数据库中读取数据。在我的数据库中,我检查数据显示为'μ'
,并且字符集已正确设置为'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>';
?>
答案 0 :(得分:4)
试试这个,
在执行实际查询之前运行以下查询:
mysqli_query($con, "SET NAMES 'utf8'");
OR
试试你的mysqli连接
$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
我希望它会有所帮助。