0

I am absolutely stuck.

I have an old website that was running on PHP4 and MySQL4. The SQL data contains slovak special characters (á, š, ť, ľ, ž etc.). The old site displays the characters fine.

I've migrated the site to a new host, it is now running on PHP 7.3 and MariaDB 10.3. I have replaced deprecated mysql_ functions with MySQLi and now the code runs fine. However, the characters are completely messed up.

I've came across multiple questions and answers, here's what I've tried:

  1. Setting charset to utf8 and/or windows-1250 to mysqli connection

    $link->set_charset("utf8mb4"); mysqli_set_charset($mysqli, "utf8");

  2. Setting both utf8 and/or windows-1250 headers to every .php file

    header('Content-Type: text/html; charset=utf-8');

  3. Re-saving each file manually with UTF8 and/or windows-1250 encoding using Sublime text

  4. Changing database collation to utf8_unicode_ci, utf8_slovak_ci and also something else

  5. Altering character sets of all tables and database

    ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci; ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

  6. Manually converting the output from UTF8 to windows-1250 using PHP's iconv (this messed up the output even more)

    $output = iconv( "Windows-1250", "UTF-8", ($output));

  7. Tried different collations when importing the old database. Also tried with and without MYSQL40 import compatibility mode in phpMyAdmin

  8. Setting both utf8 and/or windows-1250 html meta charsets

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250"> <meta charset="UTF-8">

Something that I've discovered. When I read the SQL data directly in phpMyAdmin, it displays the exact same data with messed up encoding in both old database (mysql4) and a new one. However, the old site somehow displays it correctly on the front-end.

I am really stuck, I really think I've tried every solution. What might be the problem?

Kristián Filo
  • 827
  • 2
  • 8
  • 25
  • Have you tried deleting a row/adding a new row with the same letters? Maybe the table rows messed up when the server updated. You could also try making a new database and see if the formatting is messed up on that one as well. – dobson Feb 28 '20 at 08:33
  • can you tell what should be displayed and what its displaying now? – Tausif Feb 28 '20 at 08:34
  • give your table create query with some insert data – Tausif Feb 28 '20 at 08:36
  • or attach table so that we can see whats going – Tausif Feb 28 '20 at 08:36
  • To help debug: `SELECT HEX(col), col FROM ...` to see what is in the table. – Rick James Feb 29 '20 at 08:03
  • "completely messed up" -- Which of these cases is it? https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Feb 29 '20 at 08:04

1 Answers1

0

OK. Comments by sbondo1234 and Tausif helped me to realize that the new records work just fine. Only the old data in the database is messed up. It was easier for me to create a simple matrix and pair incorrectly encoded characters with correct ones and then update them with simple SQL queries. Thanks for your help.

Kristián Filo
  • 827
  • 2
  • 8
  • 25