Home > Backend Development > PHP Tutorial > PHP Chinese garbled problem and solution_PHP tutorial

PHP Chinese garbled problem and solution_PHP tutorial

WBOY
Release: 2016-07-13 10:52:17
Original
1014 people have browsed it









$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='000000';
$mysql_database='lib';
$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
");
while($row = mysql_fetch_object($rs)){
print ($row->name.":".$row->age."
");
}
mysql_close($conn);
?>

  显示如下:

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

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

  问题补充:

  乱码:

???:15
???:25
??:32

  这几行,数据库里的值是汉字.显示出来的是问号.

  解决办法:

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

  前面加上

  mysql_query("set names gb2312");或者mysql_query("set names gbk");

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632501.htmlTechArticlehtml head title/title /head body ?php $mysql_server_name='localhost'; $mysql_username='root'; $mysql_password='000000'; $mysql_database='lib'; $conn=mysql_connect($mysql_server_nam...
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