Dariko77 Dariko77 - 1 month ago 11
JSON Question

Null php json while econde a query from mySQL with accents

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);

if (mysqli_query($conn, $sql)) {

$emparray = array();
while($row =mysqli_fetch_assoc($result)){
$emparray[] = $row;
echo json_encode($emparray,JSON_UNESCAPED_UNICODE);
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);

my database:

id | name |

1 | Olá |


json_encode assumes that the result is encoded in UTF-8, if it is not returned null

first verify that your database server is configured with UTF_8

or add the set_charset before the consultation


Use header to modify the HTTP header, UTF-8 all the way through

header('Content-Type: text/html; charset=utf-8');