This section provides a quick summary on inputting Chinese characters into MySQL database through Web forms.
Inputting Chinese characters into MySQL database through Web forms requires that:
The Web browser must display page text and collect form input text in UTF-8 encoding.
The Web browser takes the encoding name, utf-8, from the Content-Type setting in the Web page HTML document.
The Web browser must communicate text data in UTF-8 encoding with the PHP engine through the Web server.
MySQL server must take SQL statements with text data in UTF-8 encoding and store it in UTF-8 table columns.
MySQL server takes the encoding name, utf-8, from session variables character_set_client and
character_set_connection.
MySQL server must send back result set with text data in UTF-8 encoding.
MySQL server takes the encoding name, utf-8, from the session variable character_set_results.
In the PHP Web page script, we have to:
Use a <meta> tag to set Content-Type = "text/html; charset=utf-8"
for the Web page HTML document. This is to tell the Web browser that display page content in UTF-8 encoding
and take form input text in UTF-8 encoding.
Set two MySQL session control variables: character_set_client=utf8
and character_set_connection=utf8 when saving input text to the database table.
This is to tell MySQL server that my SQL statement is encoded as UTF-8
and keep it as UTF-8 when executing the statement.
Set one MySQL session control variable: character_set_results=utf8.
This is to tell MySQL server that result set must be sent back in UTF-8 encoding.
In addition to UTF-8, GBK and Big5 are also supported by MySQL server and Web browsers.