• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB charset in CI 1.6.0

#1
[eluser]dik_[/eluser]
Hi all,

I thought that the new options char_set and dbcollat in the DB config allow one to set what the connection's charset and collation are, unlike CI < 1.6, where I had to do this manually in system/database/DB.php, towards the bottom:

Code:
// Instantiate the DB adapter
    $driver = 'CI_DB_'.$params['dbdriver'].'_driver';
    $DB =& new $driver($params);    
    $DB->query("SET NAMES 'utf8'");
    return $DB;

However, when I upgraded, my UTF8 characters seem like garbage, and I still had to run that query to get it done properly.

Is there something I am missing?

Thanks for any input Smile

#2
[eluser]Référencement Google[/eluser]
Are you sure you upgraded all you files ?
I was having the same problem as you before 1.6 but now seems all is working perfectly for me.

#3
[eluser]dik_[/eluser]
Yup, I'm still testing locally, where I have just overwritten everything as the upgrade instructions suggest.

#4
[eluser]Référencement Google[/eluser]
Double check that you set all your DB in UTF-8 (the database + the tables)

Then, check that you have the meta Content-Type between your &lt;head&gt;&lt;/head&gt; tags:
Code:
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

Also, try to send a header by PHP before sending any HTML output:
Code:
$this->output->set_header("Content-Type: text/html; charset=UTF-8");

#5
[eluser]dik_[/eluser]
All of this stuff is set, that's why without the "set names" query I get garbage. With it in place, however, I get normal characters Wink

What language do you use?

#6
[eluser]Référencement Google[/eluser]
Looks like your function does not look like mine, I have this at the bottom of the DB.php file:

Code:
// Instantiate the DB adapter
    $driver = 'CI_DB_'.$params['dbdriver'].'_driver';
    $DB =& new $driver($params);
    
    if ($DB->autoinit == TRUE)
    {
        $DB->initialize();
    }
    
    return $DB;

Check twice that you are really using the latest version of CI.

#7
[eluser]dik_[/eluser]
that was on 1.5.4.

This is my current, 1.6.0, DB.php, including the extra line:

Code:
// Instantiate the DB adapter
    $driver = 'CI_DB_'.$params['dbdriver'].'_driver';
    $DB =& new $driver($params);
    
    if ($DB->autoinit == TRUE)
    {
        $DB->initialize();
    }
    $DB->query("SET NAMES 'utf8'");
    return $DB;

#8
[eluser]Derek Jones[/eluser]
1) did you update your database.php file per the update instructions?
2) If you did #1 and your files are properly updated, you should not need to execute your own SET NAMES query. Turn on the profiler output, and copy the queries here if you continue to have problems.

#9
[eluser]dik_[/eluser]
Hi Derek,

yes I have added the two extra options in the database config file (and those things about AR, although I don't use them).

I did the profiler test, here's my output with the extra "set names" line in DB.php:

Code:
0.0002      SET NAMES 'utf8'
0.0010      SELECT * FROM news ORDER BY n_timestamp DESC LIMIT 5
... // more app-specific queries
and here it is without it:
Code:
0.0008      SELECT * FROM news ORDER BY n_timestamp DESC LIMIT 5
... // more app-specific queries

Don't know what to say... :/

#10
[eluser]Derek Jones[/eluser]
For some reason I popped into this thread and evidently did not read the original message. Why are you instantiating the database driver like that instead of using $this->load->database()? That's why the proper queries to set the character set for communication aren't being run - your database class is not going through any of the initialization processes that it's intended to.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.