Home > php教程 > php手册 > PHP中文乱码问题及解决方法

PHP中文乱码问题及解决方法

WBOY
Release: 2016-05-25 16:53:37
Original
1307 people have browsed it

<html> 
<head> 
<title></title> 
</head> 
<body>
<?php 
$mysql_server_name=&#39;localhost&#39;; 
$mysql_username=&#39;root&#39;; 
$mysql_password=&#39;000000&#39;; 
$mysql_database=&#39;lib&#39;; 
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database); 
$sql="select name,age from mytb"; 
print($conn); 
$rs=mysql_db_query("lib","select * from mytb",$conn); 
print("n<br>"); 
while($row = mysql_fetch_object($rs)){ 
print ($row->name.":".$row->age."<br>"); 
} 
mysql_close($conn); 
?>
Copy after login

显示如下:

Resource id #1 
dd:54 
ddd:8 
??:15 
???:25 
??:32
Copy after login

mysql编码:utf8,GBK都试过了。mysql font 和命令行显示都正确。

问题补充,乱码:

???:15 
???:25 
??:32
Copy after login

这几行,数据库里的值是汉字.显示出来的是问号.解决办法,找到如下代码:


$rs=mysql_db_query("lib","select * from mytb",$conn);

前面加上

mysql_query("set names gb2312"); //或者下面语句
mysql_query("set names gbk");
Copy after login


本文链接:

收藏随意^^请保留教程地址.

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template