有人可以解释我的时候我都设置为UTF-8我不断收到那些该死UTF-8 MySQL和字符集
的MySQL
Server版本:44年5月1日
MySQL的字符集:UTF-8的Unicode(UTF-8)
我创建一个新的数据库
名称:utf8test
校对:utf8_general_ci
MySQL连接校对:utf8_general_ci
我的SQL是这样的:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE IF NOT EXISTS `test_table` (
`test_id` int(11) NOT NULL,
`test_text` text NOT NULL,
PRIMARY KEY (`test_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `test_table` (`test_id`, `test_text`) VALUES
(1, 'hééélo'),
(2, 'wööörld');
我的PHP/HTML:
<?php
$db_conn = mysql_connect("localhost", "root", "") or die("Can't connect to db");
mysql_select_db("utf8test", $db_conn) or die("Can't select db");
// $result = mysql_query("set names 'utf8'"); // this works... why??
$query = "SELECT * FROM test_table";
$result = mysql_query($query);
$output = "";
while($row = mysql_fetch_assoc($result)) {
$output .= "id: " . $row['test_id'] . " - text: " . $row['test_text'] . "<br />";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="it" xmlns="http://www.w3.org/1999/xhtml" xml:lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UTF-8 test</title>
</head>
<body>
<?php echo $output; ?>
</body>
</html>
谢谢Col. Ok让我看看你正在谈论的SQL dump。除了我的例子中的$ result = mysql_query(“set names'utf8'”)这行之外,我还有做另一个名字为utf8的?请问在哪里以及如何? – FFish 2010-05-31 18:34:29
@FFish在你输入你的sql命令的同一个地方,从SET SQL_MODE开始。是它的MySQL控制台或什么?这只是一个简单的规则:每次插入或选择数据时 - 必须设置客户端编码。 – 2010-05-31 18:39:08
好吧,SQL转储,现在我明白你的意思了。干杯 – FFish 2010-05-31 20:48:05