【问题标题】:Mysql insert encoding issueMysql插入编码问题
【发布时间】:2013-07-02 10:28:43
【问题描述】:

我正在尝试使用 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 .. 为什么编码错误?

【问题讨论】:

  • 你如何“在数据库中看到它”?也许这只是你工具的编码问题。
  • mysql_set_charset() 怎么样?
  • phpmyadmin.. 无论如何我已经尝试选择和打印,它仍然是?AS
  • 你在html中看到了错误的编码,但是什么是html编码,是UTF-8吗?
  • 这是我在 webapps 中使用 UTF-8 的参考文章:kunststube.net/frontback

标签: php mysql encoding utf-8


【解决方案1】:

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

 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 的文章,给了我一个提示)

【讨论】:

    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 2013-03-19
    • 2010-12-15
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多