Chinese Web Sites Using PHP
∟Input Chinese Text Data to MySQL Database
This chapter provides tutorial notes on saving Chinese text into MySQL database through Web forms and retrieved it back to Web pages. Topics include reviewing the communication process; testing with UTF-8, GBK and Big5 encodings.
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
Takeaways:
- Call header("Content-type: text/html; charset=xxxx") function to set the
HTTP response header line for the desired encoding, so the Web browser
will display the Chinese text correctly.
- Print '<meta http-equiv="Content-Type" content="text/html; charset=xxxx"/>'
in the HTML document header for the desired encoding, so the Web browser
can collect Chinese input text correctly.
- Define table column with CHARACTER SET xxx for the desired encoding,
so MySQL Server can store Chinese text correctly.
- Set two MySQL session control variables: character_set_client=xxxx
and character_set_connection=xxxx for the desired encoding,
so MySQL Server will not convert to other encodings when saving Chinese text
to the database.
- Set one MySQL session control variable: character_set_results=xxx
for the desired encoding, so MySQL Server will not convert to other encodings
when retrieving Chinese text from the database.
- When using PHP 7 and MySQL 8, the default encoding is UTF-8 in all settings.
In other words, you don't have to do anything, if you are using UFT-8 encoding
to support Chinese text.
- When using PHP 5 and MySQL 5, the default encoding is Latin1 in all settings.
In other words, you have to change everywhere, if you are using UFT-8, GBK, or Big5
encoding to support Chinese text.
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
Chinese Text Encoding Conversion and Corruptions
Archived Tutorials
References
Full Version in PDF/EPUB