I have a Problem getting UTF-8 encoded Strings out of a MariaDB-Database. Today I updated my XAMPP-Distro to 10.4.11-MariaDB (MySql) and PHP 7.2.29 and now a strange Problem arised wich had not occoured with the older version.
Preliminary informations:
I am importing data from a database dump from a working MariaDB-Database (productive system) to my local Database. And on the local Database the problem occours.
When I send a query on the local system to the database via PHP (mysqli) (the code is the same as on the production system) I get the wrong encoding:
If I wrap the text from the database with the following php function
utf8_decode($textFromTheDatabase);
everything works fine.
I also tried the following lines before every query but this does not change anything:
$dbConnection->set_charset('utf8');
$dbConnection->query("SET NAMES 'utf8'");
As mentioned above everything works on the production system but not on the new XAMPP installation. When I still had the old XAMPP version on my local system everything worked fine. So I think something is wrong with the configuration of my local Database or PHP or Apache?
2
Answers
Ok now I have a solution for the Problem: I updated to XAMPP 7.4.4 with PHP 7.4.4 and MariaDB 10.4.11. Then I set the character set and the collation correctly:
then it worked
Don’t use any decode functions; that just makes things worse.
Your images shows the “Mojibake” problem. The causes for that are discussed here:
Trouble with UTF-8 characters; what I see is not what I stored