no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | mysql_character_sets [2013/10/07 20:27] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== MySQL Character Sets ====== | ||
+ | |||
+ | * [[MySQL]] | ||
+ | |||
+ | MySQL, by default, uses LATIN1 encoding. | ||
+ | running this statement: | ||
+ | |||
+ | < | ||
+ | SHOW VARIABLES WHERE variable_name = ' | ||
+ | </ | ||
+ | |||
+ | === MySQL and PHP === | ||
+ | |||
+ | See what encoding PHP is using to connect as: | ||
+ | |||
+ | < | ||
+ | $link = mysql_connect(' | ||
+ | $charset = mysql_client_encoding($link); | ||
+ | </ | ||
+ | |||
+ | Likewise, you can override the setting and change it. The code must be directly after creating the MySQL connection: | ||
+ | |||
+ | < | ||
+ | $link = mysql_connect(' | ||
+ | $bool = mysql_set_charset(' | ||
+ | $charset = mysql_client_encoding($link); | ||
+ | </ | ||
+ | |||
+ | Using '' | ||
+ | |||
+ | < | ||
+ | $link = mysqli_connect(' | ||
+ | mysqli_set_charset(' | ||
+ | $charset = mysqli_character_set_name($link); | ||
+ | </ | ||
+ | |||
+ | === Global Variables === | ||
+ | |||
+ | You can change the database to use UTF8 by changing the runtime variables: | ||
+ | |||
+ | < | ||
+ | SET @@character_set_client = ' | ||
+ | SET @@character_set_connection = ' | ||
+ | SET @@character_set_database = ' | ||
+ | SET @@character_set_results = ' | ||
+ | SET @@character_set_server = ' | ||
+ | </ | ||
+ | |||
+ | === Database Configuration === | ||
+ | |||
+ | MySQL needs to be configured to use UTF8, or it will still use LATIN1 by default: | ||
+ | |||
+ | < | ||
+ | [mysqld_safe] | ||
+ | character-set-server=utf8 | ||
+ | |||
+ | [mysqld] | ||
+ | character-set-server=utf8 | ||
+ | |||
+ | [client] | ||
+ | default-character-set=utf8 | ||
+ | |||
+ | [mysqldump] | ||
+ | default-character-set=utf8 | ||
+ | |||
+ | [mysql] | ||
+ | default-character-set=utf8 | ||
+ | |||
+ | [mysqladmin] | ||
+ | default-character-set=utf8 | ||
+ | |||
+ | [mysqlcheck] | ||
+ | default-character-set=utf8 | ||
+ | |||
+ | [mysqlimport] | ||
+ | default-character-set=utf8 | ||
+ | |||
+ | [mysqlshow] | ||
+ | default-character-set=utf8 | ||
+ | </ | ||