Which Collation Is Optimal for MySQL with PHP?
Question:
For general websites with uncertain user input, is there a recommended MySQL collation? Should all encodings align, including MySQL, Apache, HTML, and PHP? Additionally, if PHP is configured to output in "UTF-8," which MySQL collation corresponds?
Answer:
Sorting Accuracy and Performance
The primary consideration in choosing a collation is its sorting accuracy and performance. The exception is utf8_bin, which compares characters in binary format.
General Collations
Language-Specific Collations
Specific language encodings (e.g., utf8_swedish_ci) include language rules that optimize sorting accuracy for those languages.
Recommendation
Unless a specific language is targeted, utf8_unicode_ci is typically recommended for its balance of accuracy and performance. For more information on Unicode character sets, refer to the MySQL manual: http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html.
The above is the detailed content of What MySQL Collation Best Suits UTF-8 PHP Websites?. For more information, please follow other related articles on the PHP Chinese website!