samb0057 wrote:When you create your MySQL tables, did you use the "utf8_general_ci" collation?
The collation makes no difference to the way the data is stored, just the way it's sorted when you fetch results. The important thing is the table charset, and getting the MySQL client, PHP and the HTML all to use the same encoding.
When you create your database table you need to include the CHARSET directive.. eg
Code: Select all
CREATE TABLE IF NOT EXISTS `advert` (
`advert_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT '',
`publish_date` date NOT NULL DEFAULT '0000-00-00',
`publish` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`advert_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
That will make MySQL store the data as UTF8 if you send it UTF8 data rather than converting it to something else.
You'll also need to put PHP's MySQL client into UTF8 mode using..
It's best to do that immediately you connect to the database.
And finally you need to make sure the page is displayed as UTF8 too... Personally I do that with a header().
Code: Select all
header("Content-Type: text/html; charset=utf-8");
There are probably easier ways to do it, but that's what works for me.