Avatar ·

How to properly configure full UTF-8 support from PHP to MySQL and browser without mojibake?

Hello everyone! I'm a beginner PHP developer, and for the second week I've been struggling with encoding issues. The site is in Russian, the database is MySQL, I seem to have configured everything, but when outputting data from the database, question marks or mojibake like "Р РµСально?" appear on the page. \n\nHere's how I connect to the database:\n\n```php\n$db = new mysqli('localhost', 'user', 'pass', 'mydb');\n$db->query("SET NAMES cp1251");\n```\n\nI save files in UTF-8 without BOM, and in the page head I put ``. But when I enter Russian text through a form and save it — it displays normally in the database, but not on the page. If I enter data directly through phpMyAdmin, it displays correctly on the page.\n\nI tried changing `cp1251` to `utf8` — then everything breaks in the database, but displays normally on the page. I tried `SE