Q: $SITE_INFO['database_charset'] setting.

Post

Posted
Rating:
#5110 (In Topic #1031)

utf-8 vs. utf8

Hello,

In the _config.php:

I had set:
$SITE_INFO['database_charset'] = 'utf-8';

and my site works great, the english & japanese display as needed….

I then was attempting to install the ecommerce addon and it errors out unable to create the new tables due to not recognizing utf-8…. to fix this I changed the $SITE_INFO['database_charset'] = 'utf8';  and now ecommerce installs and works fine…

but… now my japanese text is all scrambled….  to fix this I changed back to
$SITE_INFO['database_charset'] = 'utf-8';
Now my Japanese texts display properly…

utf-8 vs. utf8

Maybe I should have left that setting blank as suggested…. but wanted to share this experience.


Post

Posted
Rating:
#5113
Ah right.

This is a subtle thing.

ISO standards says it is written "utf-8". MySQL says it is written "utf8".

When you have the setting at "utf-8" MySQL is ignoring it in terms of how it is communicating with your database. However, it is not when it is creating tables - it tries to create the tables with it, which will fail.

Likely your database tables are actually in latin1 (hence why things mess up when you set it to "utf8"), I assume because you upgraded from ocPortal 9. We switched to utf-8 with Composr 10.

The best fix is to export the database to an SQL dump, then in a text editor do a string replace of latin1 to utf8. Then reimport it. Then remove the database_charset setting.

Hopefully that works for you. Charsets are confusing, my advice may not be quite right depending on what exact tools you use. Essentially you should ensure your .sql file looks correct in Japanese in your text editor, and is saved as utf-8 encoding in the text editor. If that's the case, it should be good.
1 guest and 0 members have recently viewed this.