php数据数据乱码问题

来源:互联网 发布:app inventor小软件 编辑:程序博客网 时间:2024/06/07 20:44

一 介绍

1、如果建立数据库时,使用的是utf8_unicode_ci,则在php程序中需要加mysql_query("set names utf8");
2、如果建立数据库时,使用的是GBK或GB2312,则在php程序中需要加mysql_query("set names gbk");  或  mysql_query("set names gb2312");
二 代码
<html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><?php$host = "127.0.0.1";$userName = "root";$password = "root";$dbName = "db_test01";$connID = mysql_connect($host, $userName, $password) or die("数据库连接失败!");mysql_select_db($dbName, $connID);mysql_query("set names utf8");$sql = mysql_query('select * from tb_info');while($result = mysql_fetch_array($sql)){    echo $result['title'];}?></body></html>
 
三 运行结果
从基础到实战
原创粉丝点击