1

mysql_set_charset('utf8', $kontaktmySQL);I have been trying to figure this one out for a day no, and I am getting nowhere..

I am trying to set up a simple php calendar with mysql connection, but when I load the content from my database I get small black squares with questionsmark in them. This has to do with the charset properties, but I have tried and tried and tried different solutions and I cant get it to read properly.

I have set the mysql database to use utf8_unicode (both database and tables), I have set my codeprogrammer to save my files in utf8, I have set my charset in my header (), and I even have tried to set my mysql charset after connecting to the database, but before loading the content (mysql_set_charset('utf8',$kontaktmySQLs);). I tried to find the default charset in my apache config file, but I had no luck whith that.

I have restarted xampp and nothing changed.

My system is running on a mac osx, and I have xampp installed. I am using Coda2 to program and firefox as browser. I am from norway, I need my special characters..:)

Does anyone have a clear idea of how to fix this? I am going mental..

EDIT:

I worked it out, doing the following:

  1. I had allreday set my header to: <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> so I didnt have to do anything there.

  2. Use this line: mysql_set_charset('utf8', .......); in my database connection script, right after connecting to mySQL, but before connecting to the database.

  3. Delete and create my database all over, this time being sure to set the collation to: utf8_unicode_ci both for the database and the tables.

Thanks for helping!!

  • 2
    Read [UTF-8 all the way through](http://stackoverflow.com/a/279279/623041). – eggyal Sep 16 '12 at 00:05
  • Thanks eggyal, I had not come across that post, in the end it was just a stupid misstake on my part. I was testing on a copy of my original file, and somehow i mixed them up, when I got that sortet it worked perfectly. – Vegar von Vallestad Sep 16 '12 at 11:58

1 Answers1

1

You can use a starting query:

$query = "SET NAMES 'utf8'"; // this will set all results to UTF8 encoding.
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107