Home >Database >Mysql Tutorial >How Can I Correctly Convert Latin1 Characters in a UTF8 MySQL Table to UTF8?
Convert Latin1 Characters in a UTF8 Table to UTF8
You've encountered an issue where characters with diacritics (e.g., "Jáuò Iñe") were incorrectly stored in a UTF8 table due to a missing "mysql_set_charset('utf8')" call.
To resolve this, you're attempting to convert the affected rows using "mb_convert_encoding" and "iconv." However, these methods are failing to capture characters beyond the first "illegal" character (represented as "ă" in the example).
The recommended approach to correct the data is to use the MySQL function:
convert(cast(convert(name using latin1) as binary) using utf8)
Explanation:
In some cases, the inner conversion may not be necessary, as the data may already be stored in a binary format suitable for conversion to UTF-8. Testing both options should determine the correct approach for your situation.
The above is the detailed content of How Can I Correctly Convert Latin1 Characters in a UTF8 MySQL Table to UTF8?. For more information, please follow other related articles on the PHP Chinese website!