• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySQL latin1 to UTF8 site

#1
Exclamation 
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';
$db['default']['dbcollat'] = 'latin1_swedish_ci'

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

#2
Set your DB to latin and set your output to utf-8 in config.php :

PHP Code:
$config['charset'] = 'UTF-8'
Reply

#3
(12-13-2014, 06:03 PM)includebeer Wrote: Set your DB to latin and set your output to utf-8 in config.php :


PHP Code:
$config['charset'] = 'UTF-8'

Do you mean set database options like :
PHP Code:
$db['default']['char_set'] = 'latin1';
$db['default']['dbcollat'] = 'latin1_swedish_ci'

My configuration is already like that.

Database and tables are set to latin, charset in config.php is UTF-8.

What am I missing ?
Reply

#4
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";
$db['default']['dbcollat'] = "latin1_general_ci"// or latin1_swedish_ci 

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()

Reply

#5
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. Confused
Reply

#6
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
$db['default']['dbcollat'] = "latin1_general_ci"// or latin1_swedish_ci 

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

#7
Your welcome and if you can try in the future only go with utf8 ;o)

Reply

#8
(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 ! Cool
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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