Home >Backend Development >PHP Tutorial >mysqli_connect_error 乱码

mysqli_connect_error 乱码

WBOY
WBOYOriginal
2016-06-23 13:54:501425browse

代码如下

header("Content-Type: text/html; charset=utf-8");$db_host='127.0.0.1';$db_host='192.168.0.22';$db_user='root';$db_pwd='';$db_name='iq1';@$mysqli=new mysqli($db_host,$db_user,$db_pwd,$db_name);if (mysqli_connect_errno()){	$str='<fieldset><legend>数据库连接失败</legend>';	$str.="<p>可能的原因有:数据库防火墙未关闭、数据库服务未启用</p>";	$str.="<p>返回的错误信息是 %s</p>";	$str.="</fieldset>";	printf ($str,mysqli_connect_error());	exit();};?>

 文件编码为UTF-8 

浏览器显示 结果为


移除
header("Content-Type: text/html; charset=utf-8");


将文件保存为 GB2312 页面显示正常,求解?


回复讨论(解决方案)

那是因为 mysqli_connect_error() 返回的信息是 gbk 的
你要 utf-8 的话就转一下码

printf ($str, iconv('gbk', 'utf-8', mysqli_connect_error()));

那是因为 mysqli_connect_error() 返回的信息是 gbk 的
你要 utf-8 的话就转一下码

printf ($str, iconv('gbk', 'utf-8', mysqli_connect_error()));



是 mysqli_connect_error() 一个方法返回的是GBK 还是 其他函数都这样?

不很清楚,你有意制造些错误不就知道了那?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn