Chinese Web Sites Using PHP
∟Input Chinese Text Data to MySQL Database
∟Summary
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 Content-Type = "text/html; charset=utf-8"
for the HTTP response header and 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 many versions of
Apache, PHP, MySQL Server and Web browsers.
Table of Contents
About This Book
PHP Installation on Windows Systems
Integrating PHP with Apache Web Server
charset="*" - Encodings on Chinese Web Pages
Chinese Characters in PHP String Literals
Multibyte String Functions in UTF-8 Encoding
Input Text Data from Web Forms
Input Chinese Text Data from Web Forms
MySQL - Installation on Windows
MySQL - Connecting PHP to Database
MySQL - Character Set and Encoding
MySQL - Sending Non-ASCII Text to MySQL
Retrieving Chinese Text from Database to Web Pages
►Input Chinese Text Data to MySQL Database
Steps and Application Components Involved
Inputting Chinese Text to MySQL Database in UTF-8
Inputting Chinese Text to MySQL Database in GBK
Inputting Chinese Text to MySQL Database in Big5
►Summary
Chinese Text Encoding Conversion and Corruptions
Archived Tutorials
References
Full Version in PDF/EPUB