I am using a PHP 5.2.17 server + MySQL 5.1.65.
I have a table containing a field that is VARCHAR utf8_general_ci and I fetch a record from this table.
This is how I open the connection, nothing special:
$link = mysql_connect('localhost', 'user', 'pass');
I need to respond with a JSON object that contain special characters Unicode escaped, I mean the \u00e1 notation.
$result = mysql_query(sprintf("select * from data t where t.domain='%s'", escape($domain));
while($row = mysql_fetch_array($result)) {
$r[] = array(
"tagid" => $row['DATAID'],
"name" => $row['NAME']
);
)
$encoded = json_encode($r);
header('Content-type: application/json');
exit($encoded);
My problem is fields containing special characters (áé..) are returned as null in the JSON response.
After having Googled for a while I see that PHP 5.2 lack the json_encode parameters, so I need to unicode-escape name fields manually. But how could I do this?