I have mysql 8 and its encoding is 'utf8_general_ci'. As I am from slovakia, we have a lot of special characters including 'ľ,š,č,ť,á...'. I also have rest api implemented with php. Here is the problem. When I send post request with the data, php saves the record appropriately and it can be clearly seen via phpmyadmin. However, when I'm sending GET request, the special chars are replaced with �.
Therefore, it's clearly problem with encoding. But here is the catch, I've skimmed through handful of sites and added everything that seemed to be necessary:
mysql's encoding is:'utf8_general_ci'
Database connection is the following:
$this->conn = new PDO($dsn, $this->username, $this->password);
$this->conn->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
Headers sent from php:
header("Access-Control-Allow-Origin: https://domain.sk/");
header("Content-Type: application/json; charset=utf-8");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type; Access-Control-Allow-Headers, Authorization, X-Requested-With");
On the frontend, I am using react and the meta tag in the index.html (build) is the like the one below:
<html lang="en"><head><meta charset="utf-8"/><link rel="
php.ini is set also:
default_charset = "utf-8";
And even after all of this it is not working. Mysql, of course, stores the correct values, but why doesn't the php rest api server returnn the correct value also? By the way, the php scripts are written in UTF-8 as well.
Locally, everything is totally fine.
I'd be so grateful for any comment, as I've officially run out of any other ideas.
Thank you so much for your help. It truly means a world to me!