0

I'm using mysql database and php to insert russian characters into a table.

I'm using:

$conn->set_charset('utf-8');

into my .php page to set charset to utf-8 but, when I try to print the DB charset with:

echo "set name:".$conn->character_set_name();

it shows

set name:latin1

I've set my Table to:

utf8mb4_unicode_ci

but nothing change.

Printing the passed text from the ajax request, I can see the text written correctly.

What should I do?

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • 1
    Possible duplicate of [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Madhur Bhaiya Jul 14 '19 at 14:38

1 Answers1

2

I guess you aren't checking the return value of mysqli::set_charset(). It must be returning false because utf-8 is not a valid encoding name in MySQL; the correct name is utf8 (no dash). Or, even better, utf8mb4.

You can get a list of supported encodings with:

SHOW COLLATION;
Álvaro González
  • 142,137
  • 41
  • 261
  • 360