使用MySQL的土耳其语字符编码 [英] Turkish character encoding with MySQL

查看:164
本文介绍了使用MySQL的土耳其语字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在标题中提到了土耳其字符的问题.我在MySQL上创建了一个函数:

I'm having issues with turkish characters as I mentioned in title. I created a function on MySQL:

DELIMITER $$

CREATE DEFINER=`root`@`localhost` FUNCTION `ilgiAlaniFunc`(
            idKullanici INT, 
            ilgi_alani_ismi varchar(255) CHARSET utf8 COLLATE utf8_turkish_ci
        ) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_turkish_ci
    READS SQL DATA
    DETERMINISTIC
BEGIN
    -- Function logic here
    DECLARE ret int DEFAULT -1;
    select id Into ret from ilgi_alanlari
        where ilgi_alani_adi=ilgi_alani_ismi  limit 1;
    IF(ret = -1) then
        INSERT INTO ilgi_alanlari(ilgi_alani_adi) values (ilgi_alani_ismi);
        SELECT last_insert_id() into ret;
    END IF;
    insert into kullanici_ilgi_alani(kullanici_id, ilgi_alani_id)
        values (idKullanici, ret);
    RETURN ret;
END

这是我运行的查询的转储:

This is the dump of queries I run:

111 Connect root@localhost on anketsis_main
111 Query   select ilgiAlaniFunc(43,'kıvılcım')
111 Query   select id Into ret from ilgi_alanlari where ilgi_alani_adi= NAME_CONST('ilgi_alani_ismi',_utf8'k' COLLATE 'utf8_turkish_ci')  limit 1
111 Query   insert into kullanici_ilgi_alani(kullanici_id, ilgi_alani_id) values ( NAME_CONST('idKullanici',43),  NAME_CONST('ret',54))

在这里您可以看到'kıvılcım'变成了'k'.在第一个土耳其语字符之后,MySQL会擦除所有内容.

Here you can see that 'kıvılcım' turns to 'k'. After the first turkish character MySQL erases all after that.

这是正确的转储:

120 Query   select ilgiAlaniFunc(44,'Hello')
120 Query   select id Into ret from ilgi_alanlari where ilgi_alani_adi= NAME_CONST('ilgi_alani_ismi',_utf8'Hello' COLLATE 'utf8_turkish_ci')  limit 1
120 Query   INSERT INTO ilgi_alanlari(ilgi_alani_adi) values ( NAME_CONST('ilgi_alani_ismi',_utf8'Hello' COLLATE 'utf8_turkish_ci'))
120 Query   SELECT last_insert_id() into ret
120 Query   insert into kullanici_ilgi_alani(kullanici_id, ilgi_alani_id) values ( NAME_CONST('idKullanici',44),  NAME_CONST('ret',56))

您可以看到"Hello"在任何地方都是"Hello".

As you can see 'Hello' is 'Hello' everywhere.

在我的方案中,每个排序规则都是utf8_turkish_ci. 我注意到我的问题不包括一个问题.就是这样:我怎样才能让MySQL相信我发送的字符串超出了它的想象力

Every collation is utf8_turkish_ci in in my scheme. I noticed that my question does not includes a question. So here is it: How can I make MySQL believe that I'm sending strings bigger than it thinks

推荐答案

我假设您正在从PHP发送这些查询.我可以这么说是因为你是我.

I assume you're sending these queries from PHP. I can say that because you are me.

显然,'utf8_turkish_ci'归类可以解码乱码的utf8代码,但不能解码纯土耳其语字符.通过header('Content-Type: text/html; charset=utf8');更改php文件上的编码,您可以克服此问题.

Apparently 'utf8_turkish_ci' collation can decode gibberish utf8 codes but not plain Turkish characters. Changing encodings on php files by header('Content-Type: text/html; charset=utf8'); you can overcome this problem.

这篇关于使用MySQL的土耳其语字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆