刚留了一条言为什么显示不到中文字符的?
连接数据库的代码是如下:
<?php
$link=mysql_connect('localhost','root','root')
or die ('数据库链接出错:'.mysql_error());
mysql_query("set names = 'GBK'");
mysql_select_db('guestbook');?>
字段格式:username varchar(16) gbk_chinese_ci 否
服务器:MySQL 字符集: UTF-8 Unicode (utf8)
MySQL 连接校对:utf8_general_ci
连接数据库的代码是如下:
<?php
$link=mysql_connect('localhost','root','root')
or die ('数据库链接出错:'.mysql_error());
mysql_query("set names = 'GBK'");
mysql_select_db('guestbook');?>
字段格式:username varchar(16) gbk_chinese_ci 否
服务器:MySQL 字符集: UTF-8 Unicode (utf8)
MySQL 连接校对:utf8_general_ci
插入数据库前请将字符串转码,iconv(),转成你数据库的格式
取数据时,在显示数据时候将数据转成需要的类型,如php页面编码类型
同统一数据库、php页面、模板页面、浏览器显示 的编码以上操作是常用的避免乱码的方法还有mysql_query("set names = 'GBK'");没用过,不知道管不管用,不过哪有mysql_query("set names GBK")好啊,是不是还比你的少些几个字符呢,是吧
header('Content-Type:text/html;charset=GBK');
require('common.php');
$result = mysql_query("SELECT * FROM gb_content order by id desc");//查询数据while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {// 取一条数据
?>
<table width="700" border="0" cellspacing="0" cellpadding="0" class="tb">
<tr>
<td class="bg"><b>[<?php echo htmlentities($row['username'],ENT_COMPAT,'utf-8') ?>]</b> 发表于:<?php echo htmlentities($row['insert_time'],ENT_COMPAT,'utf-8') ?></td>
</tr>
<tr>
<td><?php echo htmlentities($row['content'],ENT_COMPAT,'utf-8') ?></td>
</tr>
<tr>
<td align="right"><a href="edit.php?id=<?php echo $row['id'] ?>">修改</a> <a href="delete.php?id=<?php echo $row['id'] ?>">删除</a></td>
</tr>
</table>
<?php
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码