|
Non ASCII Characters with MySQL
Part:
1
2
3
(Continued from previous part...)
If you run it, you will get:
Default settings...
character_set_client latin1
character_set_connection latin1
character_set_database latin1
character_set_results latin1
character_set_server latin1
character_set_system utf8
character_sets_dir C:\local\MySQL\share\charsets/
Updated settings...
character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir C:\local\MySQL\share\charsets/
Creating a table in UTF-8...
Inserting some rows to the table...
Query some rows from the table...
ID Message
1 Hello!=(\x48656c6c6f21)
2 -íHola!=(\xc2a1486f6c6121)
3 S+ásŃ+!=(\xe4bda0e5a5bd21)
MySQL works as we expected, no conversion on the SQL statements, storing strings in UTF-8, and no conversion
on query result.
Conclusion
- MySQL provides a good support on non ASCII characters. If offers a number of encodings (character sets).
- MySQL allows to specify encodings at database, table or column level.
- MySQL allows to control encoding conversions on receiving SQL statements and returning query results.
- My recommendation is to use UTF-8 to all text information, turn off MySQL encoding conversion on receiving
SQL statements and returning query results, and let your PHP script to handle UTF-8 strings.
Part:
1
2
3
|