![]() |
MySQL latin1 to UTF8 site - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9) +--- Thread: MySQL latin1 to UTF8 site (/showthread.php?tid=525) |
MySQL latin1 to UTF8 site - miko91 - 12-13-2014 Hello, I begin on CI. Before I used PDO to make queries. The MySQL tables used to have latin1 charset and the site used the utf8 charset meta tag. When I wanted to insert or retrieve datas there was no problems, without configuration. Today, with CI I tried some solutions without success, like : put this in the index.php and let defaults parameters in config/database.php (utf8) PHP Code: header('Content-Type: text/html; charset=utf-8', true); or modify config/database.php like this PHP Code: $db['default']['char_set'] = 'latin1'; I would like to keep database's charset in latin1 and display datas in UTF8. Thanks for your help. PS: Sorry for my bad english. RE: MySQL latin1 to UTF8 site - includebeer - 12-13-2014 Set your DB to latin and set your output to utf-8 in config.php : PHP Code: $config['charset'] = 'UTF-8'; RE: MySQL latin1 to UTF8 site - miko91 - 12-13-2014 (12-13-2014, 06:03 PM)includebeer Wrote: Set your DB to latin and set your output to utf-8 in config.php : Do you mean set database options like : PHP Code: $db['default']['char_set'] = 'latin1'; My configuration is already like that. Database and tables are set to latin, charset in config.php is UTF-8. What am I missing ? RE: MySQL latin1 to UTF8 site - Rufnex - 12-14-2014 You should also have a meta tag in the header of your views Code: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> In your config you can try this settings PHP Code: $db['default']['char_set'] = "iso-8859-1"; It this not work i think you have to convert your date manual one of this methods from core php iconv() mb_convert_encoding() utf8_encode() and utf8_decode() RE: MySQL latin1 to UTF8 site - includebeer - 12-14-2014 Also I use htmlentities($txt, ENT_IGNORE , "UTF-8"); for all output. PS : I just read on http://php.net/htmlentities that ENT_IGNORE is not recommended. Maybe I should use ENT_SUBSTITUTE or ENT_DISALLOWED. ![]() RE: MySQL latin1 to UTF8 site - miko91 - 12-14-2014 Hello guys, After hours and some stupid changes I got the solution. Because of stackoverflow threads I tried to modify the charset of the DB. I also tried to use some utf8_encode() in my views. The good way is : header view PHP Code: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> config.php PHP Code: $config['charset'] = 'UTF-8'; database.php PHP Code: $db['default']['char_set'] = "iso-8859-1"; // or latin1 Finally, with the default configuration of CI, I've to change database.php. And I don't need any PHP function like utf8_encode() or some others to correctly display my datas. I thank you for your fast answers ! Once again, sorry for the english, I'm french and continue to learn. Edit: I set my database charset to latin1. RE: MySQL latin1 to UTF8 site - Rufnex - 12-14-2014 Your welcome and if you can try in the future only go with utf8 ;o) RE: MySQL latin1 to UTF8 site - includebeer - 12-14-2014 (12-14-2014, 07:01 AM)miko91 Wrote: After hours and some stupid changes I got the solution. Awesome ! Quote:Once again, sorry for the english, I'm french and continue to learn. No problem, my english is not very good and I speak french too ! ![]() |