This question already has an answer here:
I have problem get data from database. Persian words appear as question marks like ???????
. How can I avoid this?
Here is my code:
header('Content-Type: text/html; charset=utf-8');
$conn = mysqli_connect("localhost", "somevalue", "somevalue", "somevalue");
$output = array();
$query = "SELECT * FROM af_home ORDER BY home_id DESC LIMIT 50";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$output[] = $row;
}
echo json_encode($output);
}
</div>
make sure that the af_home
column charset is UTF-8 from the database
You can convert database UTF-8:
ALTER DATABASE your_database CHARACTER SET utf8;
-- for each table:
ALTER TABLE some_table CONVERT TO CHARACTER SET utf8;
and make sure that the table is UTF8:
SET CHARACTER SET, SET NAMES, SET COLLATION_CONNECTION