当前位置: 代码迷 >> Web开发 >> 求,为什么小弟我的这个代码反馈回来的中文全是问号
  详细解决方案

求,为什么小弟我的这个代码反馈回来的中文全是问号

热度:114   发布时间:2012-06-08 12:55:24.0
求高手指点,为什么我的这个代码反馈回来的中文全是问号?
<?php
header("content-type: text/html;charset=utf-8");
$mysqli=new mysqli ("localhost","root","root","数据库名");
if($mysqli->connect_error){
die ("连接失败".$mysqli->connect_error);
}
$sql="select * from 表名";
$res=$mysqli->query($sql);
while($row=$res->fetch_row()){
foreach($row as $key=>$val){
echo"--$val";
}
echo"<br/>";
}
$res->free();
$mysqli->close();
?>


------解决方案--------------------
mysql字段用的什么编码
页面编码与之 一致。
------解决方案--------------------
PHP code
header("content-type: text/html;charset=utf-8");
$mysqli=new mysqli ("localhost","root","root","数据库名");
if($mysqli->connect_error){
    die ("连接失败".$mysqli->connect_error);
}
$mysqli->query('SET NAMES utf8'); //加上这一行
...

------解决方案--------------------
页面 数据库操作 数据库 三方面 编码一致

1.Mysql 字段属性 utf8_general_ci
2.mysql_query("set names 'utf8'"); 
3.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  相关解决方案