MerryChristmas's avatar

UTF-8 characters saving by Eloquent but deformed by mysqli()

I'm saving data to database (MariaDB) via Eloquent. Table and fields are set utf8mb4_general_ci.

  • If I retrieve them with Eloquent, they come out fine.
  • If I try to retrieve them via PHP script they will come up deformed:
$mysqli = new mysqli('localhost', 'root', 'root', 'database');
$mysqli->set_charset("utf8mb4");

For example instead of á I will get \u00e1.

I'm not really sure it is Laravel problem ... I'm probably just doing something wrong.

0 likes
1 reply
MerryChristmas's avatar

It was caused by json_encode(). Fixed by:

json_encode($response, JSON_UNESCAPED_UNICODE);

// JSON_UNESCAPED_UNICODE (int)
// Encode multibyte Unicode characters literally (default is to escape as \uXXXX).

Please or to participate in this conversation.