Reputation: 402
I'm trying to add a new record to my MySQL table but I'm getting the following error:
An exception occurred while executing 'INSERT INTO team_mate (id, first_name, cached_sessions_count, created_at, updated_at)
VALUES (?, ?, ?, ?, ?)'
with params ["\xb6\xc4\xcf\x4e\x19\xcc\x43\x04\x82\x63\x79\x31\xec\x21\x5e\x66", "\x3f\x89\x6c\x69\x73\x65", 0, "2019-10-28 20:11:42", "2019-10-28 20:11:42"]:
SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\x89lise' for column 'first_name' at row 1
What is very weird is that inserting a new record named Élise doesn't work (and produces this error), but inserting aÉlise does work, in fact the error only happens when the first byte or first character of the field contains an accentued character.
Setup :
utf8mb4
team_mate
has collation utf8mb4_unicode_ci
first_name
in my table has collation utf8mb4_unicode_ci
The result of show variables like '%colla%';
performed from the connection:
collation_connection = utf8mb4_unicode_ci
collation_server = utf8mb4_unicode_ci
collation_database = utf8mb4_unicode_ci
The result of show variables like '%charac%';
performed from the connection:
character_set_client = utf8mb4
character_set_connection = utf8mb4
character_set_database = utf8mb4
character_set_filesystem = binary
character_set_results = utf8mb4
character_set_server = utf8mb4
character_set_system = utf8
Thanks!
Upvotes: 2
Views: 85
Reputation: 402
Ok, nevermind, I shouldn't have blamed Symfony/Doctrine/MySQL... After some debugging, I discovered that I had this function in the code:
public function setFirstName(string $firstName): self
{
$this->firstName = mb_strtoupper(substr($firstName, 0, 1)).substr($firstName, 1);
}
It was supposed to uppercase the first character, but because the first character extends over more than one byte, this creates wrong bytes that prevent the insertion in the database. I replaced substr
by mb_substr
and everything was working smoothly then!
Problem solved, thanks Ayrton!
Upvotes: 1