When I try to encode on a JSON a query from MySQL database that gives me a null JSON when the words have accents eg. " olá " , " à " etc
my php code:
$sql = "SELECT `name`
FROM `login`
WHERE `id`='1';";
$result = mysqli_query($conn, $sql);
$emparray = array();
while($row = mysqli_fetch_assoc($result)){
$emparray[] = $row;
}
echo json_encode($emparray,JSON_UNESCAPED_UNICODE);
my database:
id | name |
1 | Olá |
JSON_UNESCAPED_UNICODEconstant was added in php 5.4 meaning if you are on an older versionjson_encodewould return null and throw a notice (undefined constant) and warning (invalid argument) errors. Outside of that, I don't see an issue with the code (3v4l.org/HqIvU) so I would start with the usual, check the error logs.