Home >Backend Development >PHP Tutorial >mysqli_connect_error 乱码解决思路

mysqli_connect_error 乱码解决思路

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:00:421508browse

mysqli_connect_error 乱码
代码如下

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

 文件编码为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()));

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