-2

So I'm having some countries in a mysql tables, the problem is that when I list the countries it list them with some funny charcters, I've also had a look into the database an they are the same in the database too.

Here you have an image, on how the results look, I've tried mb_convert_encoding(string,"UTF-8") but that doesn't do anything, do you know how can I fix these?

enter image description here

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
  • Try with **SET NAMES UTF8;** – blue Apr 02 '14 at 09:32
  • So, the data in the database contains funny characters, and they show up exactly the same when output...? Hmm... That means your data contains funny characters, period. Likely it's been screwed up when it was entered into the database. See [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/) – deceze Apr 02 '14 at 09:38
  • @deceze I've faced this before and it is not a duplicate of UTF-8 all the way through. That involves setting up a new database with UTF 8, but this involves changing the character encoding of an existing database. Not that straightforward. – Nacht Blaad Apr 02 '14 at 09:40
  • Yeah, the thing is that the database is from a client, so I'm trying to do some encoding on the fly with php... – user2885793 Apr 02 '14 at 09:42
  • @Nacht It applies insofar as the data should have been inserted following the all-the-way-through principles. I'd guess (total stab in the dark) that the data was imported from some CSV or other format, so it probably should be reimported with the correct settings. – deceze Apr 02 '14 at 09:43
  • 1
    @user Then look at http://stackoverflow.com/questions/20237474/strange-character-encoding-of-stored-data-old-script-is-showing-them-fine-new/20237671#20237671 – deceze Apr 02 '14 at 09:44
  • @deceze That looks more likely. I remember the solution involved converting to binary first then UTF8. – Nacht Blaad Apr 02 '14 at 09:48
  • @user2885793 Do you have rights to change the structure of the DB or the tables? – Nacht Blaad Apr 02 '14 at 09:49
  • @deceze that solved my answer using `SELECT CONVERT(BINARY CONVERT(cn_official_name_en USING latin1) USING utf8)` maybe you can post it as an answer – user2885793 Apr 02 '14 at 09:55

1 Answers1

-1

Use below before your final query - "mysql_query("set names 'utf8'");"