Welcome Guest, Not a member yet? Register   Sign In
Inconsistent encoding returned [SOLVED]
#1

[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?
#2

[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';
$db['default']['dbcollat'] = 'utf8_general_ci';  // or utf8_unicode_ci which is what I use.

InsiteFX
#3

[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.
#4

[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/U...odeIgniter
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB