search
HomeBackend DevelopmentPHP Tutorialmysqli_connect_error 乱码

代码如下

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
php 导入csv乱码问题怎么办php 导入csv乱码问题怎么办Nov 21, 2022 am 09:32 AM

php导入csv乱码问题的解决办法:1、构造一个解析函数“function tb_str_getcsv($string, $delimiter=',', $enclosure='"') {...}”;2、读取文件到变量;3、通过“substr($s,2)”去掉BOM头即可。

cmd php乱码怎么办cmd php乱码怎么办Nov 22, 2022 am 10:29 AM

cmd php乱码的解决办法:1、在windows平台的cmd或shellpower中,执行php脚本并检查是否乱码;2、通过在php脚本里执行“exec("CHCP 65001");”命令去修改当前页码字符集即可。

php+fread()乱码怎么办php+fread()乱码怎么办Jan 18, 2023 am 10:21 AM

php+fread()乱码是因为输出页面的编码和被读文件的编码不一致,其解决办法:1、打开相应的PHP文件;2、通过fread函数读取文件;3、通过“iconv('gbk', 'utf-8', $data)”方法将读取的内容转码即可。

linux命令行显示乱码怎么办linux命令行显示乱码怎么办Mar 03, 2023 am 09:30 AM

linux命令行显示乱码的解决办法:1、通过“echo $LANG”命令查看当前支持的语言;2、使用“LANG=en_US”命令修改语言为英语语系即可解决乱码问题。

如何解决php写入数据库中文乱码问题如何解决php写入数据库中文乱码问题Sep 25, 2021 am 10:29 AM

php写入数据库中文乱码的解决办法:1、创建数据库并设置“utf8_general_ci”编码;2、用PHP读写数据库,然后设置“mysql_query("set names 'utf8'");”即可。

wordpress后台乱码怎么办wordpress后台乱码怎么办Feb 03, 2023 pm 01:48 PM

wordpress后台乱码的解决办法:1、在wordpress的“wp-admin”文件夹下找到“admin.header.php”文件;2、将“charset”属性值设置为“UTF-8”格式即可恢复正常。

mysql注释乱码问题怎么解决mysql注释乱码问题怎么解决Feb 13, 2023 am 09:44 AM

mysql注释乱码问题的解决办法:1、通过“show variables like '%colla%';show variables like '%char%';”命令查看数据库与服务端的字符集设置;2、通过“set character_set_client=utf8;”设置结果集为utf8即可。

php dompdf中文乱码怎么办php dompdf中文乱码怎么办Jan 18, 2023 am 10:34 AM

php dompdf中文乱码的解决办法:1、打开前端文件;2、通过设置“@font-face {font-family:ttt;src: url(/static/font/simkai.ttf)}”引用中文字体;3、删除“dompdf_font_family_cache.php”即可。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor