UTF-8 encoding problem

Username

epiz_31181345

Error Message

None

Other Information

Sooo when I run a query in phpMyAdmin it results are correct and one of them is “Mikołaj” - as it should be.
But when I try to display the same query results on my website there is “Miko?aj” instead. What should I do?

Welcome.

Can you please provide the full query, as well as the full response? Thanks.

Basically it’s
SELECT nameFROMteam`

and as I said
phpMyAdmin (MySQL) side result:
“Mikołaj”

php result:
“Miko?aj”

I would paste screenshots also, but as newbie I’m not able to do that

SELECT `name` FROM `team`

What has worked for me is urlencodeing the value so the special characters are not stored directly. Then on your website, you can use urldecode to print the characters as they should look.

Using urlencode(), this means that ł becomes %C5%82 in your database, but if you use urldecode(), it will become ł for the browser.

Documentation for these functions:

https://www.php.net/manual/en/function.urldecode
https://www.php.net/manual/en/function.urlencode

3 Likes

This is a known problem with our hosting.

The key issue is that phpMyAdmin uses UTF-8 character encoding, but our PHP setup is not configured to use it by default. We could fix it, but doing so would break many sites in the process, which is why we can’t.

Just not using any non-ASCII characters is one way to go around it. But you could also set the connection charset in your own code to use utf8.

With PDO, you can specify the charset to use in the database connection string: PHP: PDO_MYSQL DSN - Manual

With MySQLi, you can set it with the mysqli_set_charset function: PHP: mysqli::set_charset - Manual

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.