4

我正在尝试在带有utf8_general_ci排序规则的单元格中插入 Utf-8 字符串

我的代码:

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 ...

 print mb_detect_encoding($name);
 $query = "INSERT INTO items SET name='$name', type='$type'";
 print $query;
 mysql_set_charset('utf8'); // also doesn't help
 $result0 = mysql_query("SET CHARACTER SET utf8") or die(mysql_error()); // I've added this line, but it doesn't solve the issue
 $result01 = mysql_query('SET NAMES utf8') or die("set character ".mysql_error()); // still nothing
 $result = mysql_query($query) or die(mysql_error());

我在 html 输出中看到的内容:

UTF-8 INSERT INTO waypoints SET name='ČAS', type='ts'

我在数据库中看到的内容,如name插入的行中:

?AS

现在我的字符串是 utf-8,我的表格和单元格是 utf-8 .. 为什么编码错误?

4

1 回答 1

3

好的,谢谢大家的帮助,看来我已经解决了这个问题:

 mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $link);

创建连接后立即

(尤其是这篇文章的@Bartdude,这给了我一个提示)

于 2013-07-04T12:39:30.667 回答