简体   繁体   English

MySQL和奇怪字符的编码结果

[英]MySQL and encoding result of strange character

I have a problem with relationship between MySQL and importing data into particular table. 我与MySQL和将数据导入特定表之间的关系存在问题。 Whenever the form is requested, all data that have unicode chars into it is translated to other strange characters (question mark). 每当请求表单时,所有包含Unicode字符的数据都将转换为其他奇怪的字符(问号)。

What I have tried uptil now: 我现在尝试过的内容:

  • Set MySQL db / table to use utf8_croatian_ci 设置MySQL数据库/表以使用utf8_croatian_ci
  • Set meta-data into HTML to use utf-8 encoding 将元数据设置为HTML以使用utf-8编码
  • Query the SET NAMES 'utf8' 查询SET NAMES 'utf8'
  • Set all files to be encoded over UTF-8 将所有文件设置为通过UTF-8进行编码
  • Query over mysqli_set_charset() (thanks for noticing HAL9k) 通过mysqli_set_charset()查询(感谢注意HAL9k)
  • Also added: header("Content-type: text/html; charset=utf-8"); 还添加了: header("Content-type: text/html; charset=utf-8");
  • Tried editing my.ini and php.ini to set default charset to UTF-8 尝试编辑my.iniphp.ini以将默认字符集设置为UTF-8

Letter transformation into DB: 将字母转换为DB:

  • č, ć is translated into ?, ? č, ć转换成?, ? (HTML & DB) (HTML和DB)
  • ž is translated into (HTML, in database it's the real character 'ž' - not translated) ž被翻译成 (HTML,在数据库中为真实字符' 未翻译)

My meta: 我的中继:

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

Code (Pseudo): 代码(伪):

$con = mysqli_connect($host, $db_user, $db_pass, $db_name) or die("Error.");

// Spremanje rekorda preko UTF-8 karaktera
mysqli_query($con, "SET NAMES 'utf8'");  // ovo je bolji način :-)

$selekt = "UPDATE proizvodi SET ..
                            WHERE   slug='...'";

Don't hate me for procedural style. 不要讨厌我的程序风格。 :-) Cheers and thank you. :-)干杯,谢谢。 Suggestions please. 请提出建议。

Please try this in your db/table structure 请在您的数据库/表结构中尝试

utf8_general_ci utf8_general_ci

if this not work please find your current character set the code is below 如果这不起作用,请找到您当前的字符集,代码如下

if (!mysqli_set_charset($link, "utf8")) {
        printf("Error loading character set utf8: %s\n", mysqli_error($link));
    } else {
        printf("Current character set: %s\n", mysqli_character_set_name($link));
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM