0

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);
}
clemens
  • 16,716
  • 11
  • 50
  • 65

2 Answers2

1

make sure that the af_home column charset is UTF-8 from the database

Mohamed hesham
  • 130
  • 1
  • 12
0

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