4

Inserting Norwegian characters in my application through browser input (php) works fine (json data subsequently returned by the server is correct). But when I insert data using MYSQL dump the records get corrupted, and json returned by the server then shows NULL in place of the Norwegian characters.

Any ideas?

mtmacdonald
  • 14,216
  • 19
  • 63
  • 99
Kanchan
  • 1,609
  • 3
  • 22
  • 37

1 Answers1

2

Sounds like a character encoding issue. Which character encoding are you using?

Perhaps try this?

mtmacdonald
  • 14,216
  • 19
  • 63
  • 99
  • Hi MMacdonald, I'm using - utf8_unicode_ci – Kanchan Oct 22 '12 at 08:11
  • 1
    Have you checked that the character encoding of the dump file is also UTF8? Both the file and the database should have matching encodings. http://notepad-plus-plus.org/ is a good tool for checking the file encoding. – mtmacdonald Oct 22 '12 at 12:11
  • 1
    Hi, I checked a lot of time Both database having utf8. – Kanchan Oct 23 '12 at 10:32
  • As well data is looking good in table .. but it's printing null in php json responce – Kanchan Oct 23 '12 at 10:34
  • What about this: http://stackoverflow.com/questions/1972006/json-encode-is-returning-null – mtmacdonald Oct 23 '12 at 10:40
  • Now little bit i moved ahead by using - $pdo->exec("SET CHARACTER SET utf8"); OR $pdo->exec("set names utf8"); Now output is coming as code - "R\u00c5KV\u00c5G" for "RÅKVÅG" – Kanchan Oct 23 '12 at 12:08
  • Good, u00C5 is the correct code for 'Å'. Your JSON decoder (e.g. web browser) should decode the unicode escape for you - have you tried? If you need to print unescaped unicode directly using PHP, look at the JSON_UNESCAPED_UNICODE option for json_encode() in the PHP docs (php 5.4.0 or later). – mtmacdonald Oct 23 '12 at 12:35