0

I just copied a website to a new server (files + db) then I have the exact same php scripts and the exact same db. I have that table :

CREATE TABLE `cours` (
  `idcours` int(11) NOT NULL,
  `titrecours` varchar(256) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

And that record :

INSERT INTO `creforma_cours` (`idcours`, `titrecours`) VALUES
(-1040, 'Démonstration');

The HEX value for Démonstration is 44C383C2A96D6F6E7374726174696F6E (checked in original and new db)

I display that value with php print without any decoding (the php file if in UTF8 no bom). On the original website, it is displayed Démonstration but on the new one it is displayed Démonstration.

How can it be different ? Is there a configuration of php or mariadb-server that can prevent decoding ?

Entretoize
  • 2,124
  • 3
  • 23
  • 44
  • 2
    You have *literally* the characters "é" in your database. That's… messed up. Literally. You have messed up your database data. You need to fix that. You don't want garbage stored in your database, you want "é" instead. It happened to decode on your old server through some (un-)fortuitous combination of mistreating that garbage in reverse. On your new server, you apparently have set up all the encoding handling correctly, and are now seeing the actual garbage you have in your database. – deceze Jan 23 '20 at 08:51
  • The answer you give doesn't reply to my question, sorry. I have a better anwser. – Entretoize Jan 23 '20 at 12:20
  • See "Mojibake" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Jan 23 '20 at 23:01

1 Answers1

0

THE BAD WAY :

I found the difference in the mysql conf file, I commented these two lines :

# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full
# utf8 4-byte character set. See also client.cnf

#character-set-server  = utf8mb4
#collation-server      = utf8mb4_general_ci

OK, it would be better to let those lines uncommented and correct all my tables but it's too much work for now. And that's a solution nobody seems to know !

THE GOOD WAY :

I find the solution to correct the whole database(s) at once here :

mysqldump -p --skip-set-charset --default-character-set=latin1 --all-databases > dump.sql
mysql -p --default-character-set=utf8 < dump.sql
Entretoize
  • 2,124
  • 3
  • 23
  • 44