Reputation: 2362
I am using this PHP script
<?php
mysql_connect("blabla", "blabla", "blabla") or die(mysql_error());
mysql_select_db("blabla") or die(mysql_error());
$q=mysql_query("SELECT * FROM table ORDER BY id DESC");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
The output is Json. In the mySQL database there are entries with "ü,ä, ö" (German) For entries containing an "ü, ä, ö" the value is "null". I cannot figure out what is the problem with these characters.
Upvotes: 1
Views: 2587
Reputation: 2983
Hade the same issue with swedish charset from php to js via ajax and json, values containing any chars like ÅÄÖ got assigned null. The solution turned out to be fairly simple:
Consequently, the key here is to make sure to set the correct MySQL connection collation in the home page of phpmyadmin (or similar) and repetitively use the same collation throughout your db.
Upvotes: 0
Reputation: 324650
Call utf8_encode
on each string value before passing them to json_encode
.
Upvotes: 1