UTF8 data from MySQL - SOLVED

UTF8 data from MySQL - SOLVED

matbeardmatbeard Posts: 22Questions: 0Answers: 0
edited April 2012 in General
I just thought I'd share a tip with anyone having problems with 'special' characters from MySQL and JSON.

If you're data is stored as UTF8 in MySQL, the provided server-side PHP code won't handle it properly, and certain characters will be returned as �.

The [code]json_encode($output)[/code]

at the end of the script will return 'null' when it encounters this.

The fix is simple... add the following after the connection:
[code]mysql_query("set names 'utf8'",$gaSql['link']);[/code]

Hope this helps... took me a bit of hair-pulling before I found it.
This discussion has been closed.