Sorry if this has been asked before but I could not find a solution. My PHP script returns blank when the data contains an accent and I get no error. How to solve this, please?
My collation is ut8_general_ci
.
The server uses PHP 7.
Here is the code:
include ("connectDB.php");
$q = "select id, nom from atelier WHERE session = '2'";
$sql = $mysqli->query($q);
$data = array();
while($row = mysqli_fetch_array($sql, true)){
$data[] = $row;
};
header('Content-Type: application/json');
echo json_encode($data);
Here is the structure of the table:
EDIT: here is the working code
<?php
include ("connectDB.php");
mysqli_set_charset($mysqli,'utf8');
$q = "select id, nom from atelier WHERE session = '3' ORDER BY nom";
$sql = $mysqli->query($q);
$data = array();
while($row = mysqli_fetch_array($sql, true)){
$data[] = $row;
//echo json_last_error(); // returns 5 ?
};
header('Content-Type: application/json');
echo json_encode($data,JSON_UNESCAPED_UNICODE);
?>