我有一个 MySQL 问题。除了我的数据库之外,我的整个网站都是 UTF8 格式的。我最近刚刚尝试使用各种命令将其转换为 UTF8,但主要问题仍然存在:
口音不起作用。而不是é,我有é。è 也一样,还有另一种奇怪的字符。
是否有一个简单的转换所有这些字符的方法,比如说 é,到 é,在基地?
多谢。
(顺便说一下,数据库在latin1)
我有一个 MySQL 问题。除了我的数据库之外,我的整个网站都是 UTF8 格式的。我最近刚刚尝试使用各种命令将其转换为 UTF8,但主要问题仍然存在:
口音不起作用。而不是é,我有é。è 也一样,还有另一种奇怪的字符。
是否有一个简单的转换所有这些字符的方法,比如说 é,到 é,在基地?
多谢。
(顺便说一下,数据库在latin1)
在这种情况下,é
被é
解释为 LATIN1 并转换为 UTF-8。可能是您的数据库试图提供帮助并转换为不需要转换的 UTF-8。
您是否尝试过切换数据库表上的字符集?
你可以试试这个功能:
CREATE TABLE `utf8decodemap` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`encoded` VARCHAR(128) NOT NULL,
`decoded` VARCHAR(128) NOT NULL,
UNIQUE KEY urlcodemapUIdx1(encoded),
PRIMARY KEY (`id`)
);
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("â","â");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("é","é");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("è","è");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ê","ê");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ë","ë");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("î","î");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ï","ï");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ô","ô");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ö","ö");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ù","ù");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("û","û");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ü","ü");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("ç","ç");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("œ","Å?");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("€","â¬");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("°","°");
INSERT INTO utf8decodemap (decoded,encoded) VALUES ("à","Ã");
DELIMITER $$
CREATE FUNCTION `utf8decoder`(str VARCHAR(4096)) RETURNS VARCHAR(4096) DETERMINISTIC
BEGIN
DECLARE X INT;
DECLARE chr VARCHAR(256);
DECLARE chrto VARCHAR(256);
DECLARE result VARCHAR(4096);
SET X = 1;
WHILE X <= (SELECT MAX(id) FROM utf8decodemap) DO
SET chr = (SELECT `encoded` FROM utf8decodemap WHERE id = X);
SET chrto = (SELECT `decoded` FROM utf8decodemap WHERE id = X);
SET str = REPLACE(str,chr,chrto);
SET X = X + 1;
END WHILE;
RETURN str;
END$$
DELIMITER ;
例如:从 MYtable 中选择 utf8decoder(MyCol)