网上查了说是没有设置编码,数据库的编码是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>
在连接数据库后,加上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'");