I have a php script that copies data from 1 table to another.
The source table and its fields are utf8mb4_general_ci while the target table and its fields are utf8mb4_unicode_ci.
I get an "Incorrect string value" each time the script tries to insert a special characte like "è".
The DataBase version is 8.0.36-28. The script used to wok well with 5.6.51-91.0-log DB version.
I tryed with and without mb_convert_encoding, the result is the same.
2
Answers
Different encoding can be a real pain.
And confusing.
I advise you to have a look at iconv(). it can change encoding1 to encoding2:
iconv
Or, if you want to dive a bit deeper, follow the link by KIKO software in the comment.
utf8mb4_general_ci
andutf8mb4_unicode_ci
are different_COLLATIONs_
of the same encoding —utf8mb4
.If you are bringing the data into PHP and then sending it back out, the likely villain is found in
SHOW VARIABLES LIKE 'char%';
Please run that and show us the result.The best fix is to connect with utf8mb4; second best is to run
SET NAMES utf8mb4;
right after connecting.mb_convert_encoding
(and any other conversion tool) will only make things worse.Simply using SQL to migrate the data may be better:
or
The latter syntax lets you add/remove columns (etc) at the same time as you copy the data. However, any expressions may involve the
COLLATION
and cause trouble.Let’s see your "copy" code.