Welcome Guest, Not a member yet? Register   Sign In
SET NAMES in db class
#1

[eluser]lay-z-cow[/eluser]
Hi there,

I'm new to codeIgniter and first of all I want to compliment you guys, because you made one of the best documentations I've ever seen.

But I got still a question:
I always want to take care of the right encoding of my characters (ie. umlauts). Because I don't want to handle with HTML entities I work with UTF-8 encoding throughout all techniques.

This means I always send a "SET NAMES = 'UTF-8'" query to the database, when I initialize a new connection. This works very well and I would like to keep it that way.

So my question: Is there any possibility to set this up, by using the given functionalitites or do I have to change it directly in the sourcecode?


Best Regards from Germany, Smile

Christian
#2

[eluser]tobben[/eluser]
Just set it once in the DB model you are using.

Code:
class Some_model extends Model {
        
    function __construct() {

        parent::Model();
            
        $this->db->query("SET NAMES 'utf8'");
            
    }

}

..that works for me.
#3

[eluser]lay-z-cow[/eluser]
Hi,

thank you, that's how I would have done it, too.
I thought maybe there would be an option so the DB class does it for me.

Maybe it would be useful to think about integrating it, so you can activate this query by default in an additional config parameter. Because in my opinion, it's a very useful function, avoiding that you mess up your encoding.
#4

[eluser]velti[/eluser]
i just reported it as bug, but derek means it’s more a feature than a bug.

Anyway, i want to post a great article about the umlaut problem:

german:
http://www.mysqldumper.de/board/viewtopic.php?t=2313

english translation:
http://www.drummy.org/archives/37/1/

it’s 00:30 now,
good night!
velti

p.s.: i'm sorry for double posting, i accidentially created a new topic
#5

[eluser]lay-z-cow[/eluser]
@velti:

Hi,
I'm german, too. Maybe you'll also like this article, which helped me a lot:
http://blog.antikoerperchen.de/beitrag/4...ntity.html
#6

[eluser]lay-z-cow[/eluser]
With CI 1.6 this issue can be solved by

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

right?

or do i still have to "SET NAMES 'utf8'" by myself?


greets

chris

btw: very interesting changes. you guys did great one more time.. Big Grin
#7

[eluser]Derek Jones[/eluser]
You are correct chris, you no longer have to set the client communication character set on your own.




Theme © iAndrew 2016 - Forum software by © MyBB