Home > Backend Development > PHP Tutorial > PHP菜鸟,请问关于从数据库读取后输出会乱码的情况

PHP菜鸟,请问关于从数据库读取后输出会乱码的情况

WBOY
Release: 2016-06-13 12:05:41
Original
1109 people have browsed it

PHP初学者,请教关于从数据库读取后输出会乱码的情况
目前用的wampserver
数据库选择UTF8 general_CI ,页面charset使用utf8,PhpMyAdmin中夫妻链接校对使用UTF8 GENERAL CI,
然后这段代码:

<br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"><br /><html><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf8"><br /><title>Insert title here</title><br /></head><br /><br />    <body><br />    <p>This page uses frames. The current browser you are using does not support frames.</p><br />    <?php<br />$con= mysql_connect("localhost","root","root");<br />if(!$con)<br />{<br />die('Could not connect : ' . mysql_error());<br />}<br /><br />mysql_select_db("tes",$con);<br /><br />$result = mysql_query("select * from cat");<br /><br />while($row = mysql_fetch_array($result))<br />{echo $row['1'] . " " . $row['2'];<br />echo "Go<br/>瓦";<br />}<br />mysql_close($con)<br />	?><br />    </body><br /><br /></html><br /><br />
Copy after login



输出的是:

This page uses frames. The current browser you are using does not support frames.
a "乱码不给打"  123Go
瓦 
列1中的数据在数据库中是' a 啊 '  输出后乱码  求教.
------解决方案--------------------
mysql_select_db("tes",$con); 
mysql_query('set names utf8'); //加上这句
------解决方案--------------------
在哪输入,编辑器中? 那说明你的文件不是utf-8编码,用编辑器设成utf-8 无bom 头格式保存。

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