网上查了说是没有设置编码,数据库的编码是utf-8,
说是要增加mysql_query( "set names 'utf-8'");
但我在加进去无效,是我加错了地方吗,请各位赐教<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<?php
/* 连接选择数据库 */
$link = mysql_connect("localhost", "zxn", "")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("zxn") or die("Could not select database"); /* 执行 SQL 查询 */ $query = "SELECT * FROM phpsay_forum";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* 在 HTML 中打印结果 */ print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n"; /* 释放资源 */
mysql_free_result($result); /* 断开连接 */
mysql_close($link);
?>
</body>
</html>
说是要增加mysql_query( "set names 'utf-8'");
但我在加进去无效,是我加错了地方吗,请各位赐教<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<?php
/* 连接选择数据库 */
$link = mysql_connect("localhost", "zxn", "")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("zxn") or die("Could not select database"); /* 执行 SQL 查询 */ $query = "SELECT * FROM phpsay_forum";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
/* 在 HTML 中打印结果 */ print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n"; /* 释放资源 */
mysql_free_result($result); /* 断开连接 */
mysql_close($link);
?>
</body>
</html>
解决方案 »
- 如何让网站屏蔽无线网的访问?
- php连接数据库代码问题
- imac 下配置php环境更改httpd.conf遇到的问题
- 仅以此贴来广泛收集php的便捷写法,,收集~~~~~~
- 论坛会员头像问题
- 这个myslq语句该怎么写?
- 使用smtp身份验证发送邮件时提示Warning: fsockopen(): unable to connect to smtp.126.com:25 ,如何解决啊?
- adodb中哪个函数和mysql_fetch_array($result);相当?急,在线等!!!
- 在服务忙时,PHP进程被当起。
- 大家能将这段asp程序改为php的,或推荐一个php的flash留言版都送分
- PHP上传大文件,有独立服务器,有没有什么比较好的方案?
- 求一段更行数据库数据的代码(根据ID) 另外我写了一个方法大家帮我看看
在连接数据库后,加上mysql_query("SET NAMES utf8");
你那个是错的。
$link = mysql_connect("localhost", "zxn", "")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("zxn") or die("Could not select database");
mysql_query( "set names 'utf-8'");
$link = mysql_connect("localhost", "zxn", "")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("zxn") or die("Could not select database");
mysql_query( "set names 'utf-8'");