Turkish character encoding with MySQL

梦想与她 提交于 2019-12-10 22:27:50

问题


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))

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

And here is a correct dump:

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))

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

Every collation is utf8_turkish_ci in in my scheme. Edit: 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


回答1:


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

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.




回答2:


I,'ve been using notepad++ text editor and had the same problem. (despite upper solution) At the coding tab, there is a selection as code with UTF-8, i selected it and saved the file. After i sent the code to the server,it works :)



来源:https://stackoverflow.com/questions/11216079/turkish-character-encoding-with-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!