Inconsistent encoding returned [SOLVED] - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Inconsistent encoding returned [SOLVED] (/showthread.php?tid=40348) |
Inconsistent encoding returned [SOLVED] - El Forum - 04-06-2011 [eluser]JulijanAndjelic[/eluser] Hey guys, I'm experiencing a really strange issue with the charset returned by mysql query. I have: $db['default']['char_set'] = 'utf8'; $db['default']['dbcollat'] = 'utf8'; (also tried variations like UTF8, UTF-8, utf-8 but still no good) And some data stored in mysql which contains utf8 characters. Say, the letter "ž" is sometimes returned as "ž" and sometimes "ž" (which is obviously incorrect). I have the charset declaration in my page: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> I also tried setting my dbcollat to latin1_swedish_ci to match my db collat but again I've got the wrong result. Am I doing something wrong or could this be a bug? Inconsistent encoding returned [SOLVED] - El Forum - 04-06-2011 [eluser]InsiteFX[/eluser] If you have phpMyAdmin First do complete SQL dump to get all your tables, sometime changing database collation will corrupt your data and you will need to re-enter it... 1) click on your databse name 2) click on the Operations tab 3) look at the bottom and see what collation your database is set for MySQL defaults to latin1_swedish_ci If that is what it is set for change it to either utf8_general_ci or utf8_unicode_ci These should be! Code: $db['default']['char_set'] = 'utf8'; InsiteFX Inconsistent encoding returned [SOLVED] - El Forum - 04-06-2011 [eluser]JulijanAndjelic[/eluser] InsiteFX, thanks for your reply but it seems that utf8_general_ci and utf8_unicode_ci don't support ćč letters. And another thing that bothers me is why are the results inconsistent? I mean, it returns the correct result now and then, that's kinda strange and makes me think that the problem lays on place other than script/db relation. And another thing is when I use a regular mysql_connect, mysql_query, mysql_fetch_assoc it works fine with latin1_swedish_ci (which is set by default in my MySQL installation). Maybe some processing done by CI when using the db->get method? My charset in config.php is set to UTF-8. Inconsistent encoding returned [SOLVED] - El Forum - 04-06-2011 [eluser]Phil Sturgeon[/eluser] You have characters stored in the database as latin1_swedish_ci that are being converted incorectly to utf8 when you connect. You need to set everything everywhere to be totally utf8 and utf8_unicode_ci. And I mean everywhere. Your desktop MySQL client, PHP connections, default table schema and sometimes even the fields themselves. If you put utf8 everywhere (even your PHP header and HTML meta headeR) you will not have this problem. http://philsturgeon.co.uk/blog/2009/08/UTF-8-support-for-CodeIgniter Inconsistent encoding returned [SOLVED] - El Forum - 04-06-2011 [eluser]JulijanAndjelic[/eluser] Phil Sturgeon, thanks! That was helpful, the problem was that my tables and the database collation were correctly set to utf8_unicode_ci but my fields in that table were set to other collation. So I used the ALTER TABLE to modify my field collations and that fixed the problem. Therefore this is not a bug. |