The system is a PHP application accessing a MySQL database. The first tables were created with the standard latin1 encoding and filled via mysqli in PHP, without setting any encoding. The PHP scripts and data all work in UTF-8.
The newer tables have set the encoding to utf8_bin and in front of every transaction SET CHARACTER SET utf8
is sent.
If I look at the newer tables in the mysql database (via a sql explorer like HeidiSQL) every special character is displayed correctly. However, in every older table the typical latin1-utf8 errors are visible like Ü for ü.
Is there an easy way to fix this like in one of the following ways:
- Fix the encoding for each table so that is displayed correctly in the sql explorer, but keep the PHP code as it is (with
SET CHARACTER SET utf8
orlatin1
in front of every statement, fitting the tables encoding. (merely a workaround) - Switch the encoding to utf8 for all tables -> now
SET CHARACTER SET utf8
has to be sent at the beginning of every mysqli connection (or maybe there is a way to set this as standard?) - Switch the encodung to latin1 for all tables -> no need to send
SET CHARACTER SET utf8
in front of transactions anymore, but wrong encoding in the database explorer.
It seems as if the Database takes all tables as utf8 and shows latin1 tables therefore with wrong characters. Mysqli takes all tables as latin1 if not told different.
The application is productive, the encoding problem is not visible to the user, as the right encoding is told to mysqli in front of every statement. But I feel like that is not a good practice.
I recognize that there is something wrong with how the database is set up, and I hope to learn what is the best practice to fix this.