Welcome Guest, Not a member yet? Register   Sign In
Workaround for UTF8 Characters that can't be inserted into database? German Umlauts, etc...?
#1

[eluser]tschunde[/eluser]
Hi all,

I love CodeIgniter but there is one thing that makes me a little nervous... I wanted to insert a utf8 comment into my utf8 database...
somehow everything works until there are special characters like "German Umlauts" ÄÖÜ in the text o_O

After some research (I already found three entries in this board and talked to some people in the irc).

If some filtering is not working right that prevents my good little Umlauts to get inserted into db: What is the workaround in order to get them into it? Use latin-1?

Kind Regards,
tschundeee
#2

[eluser]webthink[/eluser]
Hi,

If you are using an older version of codeigniter, you will need to manually issue a SET NAMES utf8 command to mysql. If you are using a later (post 1.6) version, that should be handled for you automatically, so long as you have something like

Code:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

in your database config. Double check that your DB, and your tables, are set to use utf8. Also, unless codeigniter does this automatically, which I don't think it does, you should send

Code:
header("Content-Type: text/html; charset=UTF-8");

before any other output.

That should do it.
#3

[eluser]tschunde[/eluser]
okay I found what was the problem: the osx tool CocoaMySQL... It showed always null when there was umlauts in the text... phpmyadmin shows everything right :-)
#4

[eluser]tommebasso[/eluser]
hi tschunde,

i wonder what your setup is, since I have the same problem. I'm working on osx (10.5.) with mamp and ci 1.6.1 to develop my sites. setting up the mysql-db, -tables and -fields as utf8 doesn't resolve the problem. when I insert strings with german umlauts (äöüß), they get truncated at the char position of the first occuring umlaut (for example: straße gets stra). and phpmyadmin confirms this behaviour - no umlaut gets into the db-table.
I tried it sending $_POST-data and hard-coding some inserts in my ci-app. no chance to get the umlauts into the db. whereas when i execute the same insert-query within phpmyadmin everything's just like it should be: wonderful umlauts wherever i want them.

I'm new to ci and since i discovered this marvelous framework some weeks ago i was totally excited about developing new sites with it. now i'm getting nervous instead ...

has anybody a hint how to solve this problem?
#5

[eluser]Doosje[/eluser]
I;ve had similar problem's
Eveything in the database en uppon insert's was okay, but on the main-page i got funny char's like
Code:
é ü
and they were supposed to be a é and an ü
the thing that solved it for me was:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
#6

[eluser]nmweb[/eluser]
I'd rather use header('Content-type: text/html; charset=UTF-8'); over a meta tag though. Anyway, do take care with utf8 strings that php functions like strlen, substr etc. won't work properly.




Theme © iAndrew 2016 - Forum software by © MyBB