Home > Backend Development > PHP Tutorial > mysqli_connect_error 乱码

mysqli_connect_error 乱码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:54:50
Original
1475 people have browsed it

代码如下

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();};?>
Copy after login

文件编码为UTF-8

浏览器显示 结果为


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


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


回复讨论(解决方案)

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

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

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

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



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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template