M
M
marataziat2016-07-21 17:42:46
PHP
marataziat, 2016-07-21 17:42:46

Why do I get ???? mesto krakozyabr?

I wrote a simple script to display data from a table:

<?php
// Подключение к базе: где $hostname - сервер, $username - имя юзера БД,
   // $password - пароль юзера, $basename - имя базы с которой мы будем работать
   $hostname = 'localhost';
   $username = 'root';
   $passwordname = 'root';
   $basename = 'codebooks';
   
   $conn = new mysqli($hostname, $username, $passwordname, $basename) or die       ('Невозможно открыть базу');
   // Формируем запрос из таблицы с именем blog
   $sql = "SELECT * FROM `books`";
   $result = $conn->query($sql); 
   // В цикле перебираем все записи таблицы и выводим их
   while ($row = $result->fetch_assoc())
   {
       // Оператором echo выводим на экран поля таблицы name_blog и text_blog
       echo 'Название блога: '.$row['description'];
       echo 'Текст блога: '.$row['title'];
   }
   ?>

It is necessary for me that the text from the table was
b4bbcefd05574855accb8ba995168c16.png
deduced: but it is deduced:
a3e7d5a3240e4acd8a004fb45334979b.png??????? output??? I need at least krakozyabry :)
here is the structure of the table:
ea90c8566b98473fa6505c0017f13b8c.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2016-07-21
@melkij

set names - the solution is wrong, which even deserves a separate page in the manual: php.net/manual/en/mysqlinfo.concepts.charset.php
The solution is correct:
$mysqli->set_charset('utf8');

M
marataziat, 2016-07-21
@marataziat

so far the same

M
Michael, 2016-07-21
@springimport

I always knew:
- if you see the "text", then everything is fine;
- if you see "krakozyabry", then you will have to spend time solving the problem;
- if you see "????????????", then the encoding came full f*ck :)
If in essence. Try playing with iconv and mb_detect_encoding .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question