有人可以解釋我的時候我都設置爲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