How to set mysql charset to UTF-8 no matter the specific sql settings
I learned something new today in php / mysql development:
I'm facing the same issue every now and then, for a mailinglist script i wrote which uses mysql as data storage.
Problem is, depending on the end user server configuration, special chars such as é,è, ê, ë get wacked when saved in the database, as it sometimes is not set to use utf8.
What i've learned? You can avoid the problem by just setting the database connection to view any data being sent or retrieved as utf-8 by just opening the connection and then telling MySQL that it should set/handle all string type data as utf-8!
-
// now do your inserts and selects
You can also set this in your MySQL config file, so it's automatically done at startup!
-
[mysqld]
-
init-connect='SET NAMES utf8'
Author: pixeline
Date: June 3rd, 2007
filed in: Development
Follow the discussion on this entry via RSS 2.0 feed.
[...] So I decided to fix this issue no matter what. After searching about half an hour I bumped into a blog entry that showed the solution. Fairly easy, eh? More info in MySQL [...]