I add entries to the database table through the query and via phpmyadmin, in the table itself Cyrillic and Latin characters are normally displayed, but when receiving and displaying posts on the server Cyrillic characters are displayed with question marks. The coding of the database and pages on the server is the same utf8. Who knows what the problem is and how to solve it? Linux system

index.php

<?php require_once "templates/header.php"; ?> <?php require_once "db.php"; $result = $conn->query("SELECT `title`, `text`, `date` FROM news"); ?> <section id="news" class="news"> <div class="container"> <div class="news__wrapper"> <?php while($row = mysqli_fetch_array($result)) { ?> <div class="news__item"> <div class="news__item-heading d-flex justify-content-between align-items-center"> <h2><?= $row['title']; ?></h2> <span><?= $row['date']; ?></span> </div> <div class="news__item-content"> <?= $row['text']; ?> </div> </div> <?php } ?> </div> </div> </section> <?php require_once "templates/footer.php"; ?> 

db.php

 <?php /* Connecting to database */ $host = "127.0.0.1"; //host ip $username = "admin"; //username of database $password = "123"; //db user password $database = "news"; //database name //establishing connecting to db $conn = new mysqli($host, $username, $password, $database); //if something went wrong during connection to db if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); ?> 
  • This seems to be the most popular question on php and MySQL =) Set the coding of communication php and MySQL - Vladimir Klykov

1 answer 1

Perhaps you need to specify the encoding)

 $conn = mysqli_connect($host, $username, $password, $database); mysqli_query($conn, "SET NAMES utf8");