This is only to answer the first question#QUESTION #1
#ANSWER TO QUESTION #1
You will see that some Characters Sets have with multiple collations for Different Parts of Europe. Chinese, Japanese, Greek, and parts of Asia Minor and Scandinavia are also available.
#QUESTION #2
Should you always ensure your PHP connection matches the charset of the database you're working on?
#ANSWER TO QUESTION #2
##SCENARIO
You are driving at 3:00 AM. You are the only driver on the road. You come to an intersection. You have the red light.
##Question : Do you stop or go through the red light?
##Answer : Depends on the neighborhood
- Safe neighborhood ?
- Some abide by the law, stop at the red, and wait for green.
- Some chance it and go through
- Bad neighborhood or new to the area ?
- Some abide by the law, stop at the red, and wait for green AT THE RISK OF A CARJACKING
- Some chance it and go through to AVOID OR REDUCE RISK OF A CARJACKING
- Assume the worst and find another route
##How does this apply?
You should err on the side of caution. You should always check the charset beforehand because you do not know the neighborhood (client program, internet browser) the PHP connection will be entering and if there is a risk of a carjacking (putting invalid data into the database, requesting too much data for retrieval).
#QUESTION #3
If you can have different tables that use different character sets do you just use SET NAMES or mysql(i)_set_charset to switch?
#ANSWER TO QUESTION #3
By all means
#QUESTION #4
If you have a table that has multiple charsets how do you manage that since the connection can only use one charset at a time?
#ANSWER TO QUESTION #4
You may have to shift character sets with the DB Session. Here are the settings that can be changed at the session level:
- character_set_client
- character_set_connection
- character_set_database
- character_set_filesystem
- character_set_results
Please set these carefully before reading from and writing to the database. It would also be wise to store the character set name and collation in the same table you will be accessing.