D
D
Daniel2020-05-17 21:23:36
PHP
Daniel, 2020-05-17 21:23:36

Questions instead of Cyrillic when displaying information from MySQL?

When loading information from the database to the page, we get questions instead of symbols. Everything is displayed correctly in the database for any encoding

. I tried everything in Google - once it turned out to display correctly, but I decided to connect utf8mb4 instead of utf8 and everything broke again. After that, I changed to utf8 and utf8mb4 and cp1251 - all to no avail

. Everything works fine on the LAN, the problem occurs on the hosting

. For half a day of walking around and around, nothing helped. Here is the result of the query "SHOW SESSION VARIABLES":

5ec17e9cdd264960991462.png

Tell me, please, what
should I do with it, it's already on fire.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roma, 2020-05-18
@TheCrossCarrier

<?php
$db= mysqli_connect("localhost", "root", "", "db");
//Try this:
$huruf= $db->query("SET NAMES 'utf8'");
$huruf2= $db->query("SET CHARACTER SET 'utf8'");
$huruf3= $db->query("SET SESSION collation_connection = 'utf8_general_ci'");
?>

S
Sergey Eremin, 2020-05-18
@Sergei_Erjemin

Judging by the printscreen, the table uses different encodings for different columns. The problem may be in this. I don't know if this will help in your case, but it's worth a try:
Dump the database. Open it in a text editor. Look with your eyes at what you have in those fields that go with umlauts and other squares and questions. Try to figure out where the encoding was formed and whether it matches what was specified when creating tables and fields (the FAR Manager tool is quite suitable, it allows you to change encodings when viewing and editing. Write a script that unifies encodings when creating tables and fields, and it will also recode the field values ​​when they are filled in with data.If there is not much data in the tables, everything can even be done by hand in a text editor.
Then upload this corrected dump to the server.

F
FanatPHP, 2020-05-18
@FanatPHP

If the question marks are in plain text, then the encoding must be specified in the DSN , as shown here.
If the question marks are in diamonds, then this is the encoding of the page in the browser , not the database.
It is set either through default_charset in php.ini or stupidly
header('Content-Type: text/html; charset=utf-8');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question