0

I have a problem with PHP. In database, the whole information is written in Armenian, and I want to get that data and display it on the screen using PHP and HTML. But when I write,

$conn = new mysqli("some-host", "some-username", "some-password", "some-website");
$sql = "SELECT * FROM categories";
$result = $conn->query($sql);

while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Category: " . $row["category"]."<br>";
}

the output is:

id: 1 - Category: ????????? ?????????????
id: 2 - Category: ??????????? ?????????????
id: 3 - Category: ???

What I must to do to change "?" symbols into Armenian letters?

programmer
  • 91
  • 8

1 Answers1

0

mysql set charset


SET NAMES 'utf8'
SET CHARACTER SET utf8

Or

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;

dılo sürücü
  • 3,821
  • 1
  • 26
  • 28
  • You can also use in the php code this: $conn->set_charset("utf8") if you want to make filters such as select * from table where field='armenian chars' . OR use mysqli_set_charset($conn,"utf8"); – MihaiM Aug 29 '19 at 19:32
  • He said that he initiates a `new mysqli` object, so i belive it will be ok. – MihaiM Aug 29 '19 at 19:35
  • dılo sürücü, your version didn't work. Error appers in phpmyadmin. But MihaiM's version did work. Thanks! – programmer Aug 30 '19 at 04:26