0

I get null results after I do a ajax call, where the values have umlauts. I tried to fix this with:

$this->pdo = new PDO('mysql:host=host;dbname=db','user','password',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

The call hierarchy is that the ajax call goes to a php script search.php which have stored a dbconnection object and this is where the sql-calls are going on. I also tried to fix it with utf8_encode but it had no effect. The database is in charset: UTF-8 Unicode (utf8), too and the php version is 5.4.

In my local apache I dont get any problems. The problem apears only on the real webpage.

What do I miss?

Kingalione
  • 4,237
  • 6
  • 49
  • 84

1 Answers1

0

Change the umlauts to HTML entities by using htmlentities(), then json_encode().

kero
  • 10,647
  • 5
  • 41
  • 51
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
  • didnt helped me. I used htmlentities($products); echo json_encode($products); and also $products = htmlentities($products); but both didnt worked – Kingalione Mar 09 '14 at 23:37
  • 3
    ok, then its the database connection or encoding, which is not UTF-8. Check this: http://stackoverflow.com/a/11413251/1163786 – Jens A. Koch Mar 09 '14 at 23:40