Building Chinese Web Sites using PHP
Dr. Herong Yang, Version 2.11

Storing Non-ASCII Characters with Encoded Bytes

This section describes a test of storing non-ASCII characters with encoded bytes.

After created a table with columns with non-ASCII character sets, the next question is how to send non-ASCII characters to a MySQL server in the SQL statement.

The first test I did was to build a SQL INSERT statement with French and Chinese characters encoded into binary data with Latin1, UTF-8, GBK and Big5. Then the SQL INSET statement is sent to my local MySQL server with mysql_query() method for execution.


Here is the output of the PHP script:

C:\>\local\php\php MySQL-Insert-Non-ASCII.php
Number of rows deleted: 0
Number of rows inserted: 1

Test Name = Non-ASCII Test
   String_ASCII: 0x54656c65766973696f6e
   String_Latin1: 0x54e96ce9766973696e6f
   String_UTF8: 0x3f3f3f2f3f3f3f
   String_GBK: 0x3f3f3f
   String_Big5: 0x3f3f3f

The output tells me that:

  • The test was successful on with columns defined as ASCII or Latin1.
  • The test failed with columns defined as UTF-8, GBK, or Big5. I didn't get the same binary values as the SQL statement. See the next section for explanations.

Sections in This Chapter

Specifying Character Set for Text Columns

Creating a Table with Multiple Character Sets

Checking Character Set Setting

Storing ASCII Characters in Non-ASCII Columns

Storing Non-ASCII Characters with Encoded Bytes

Transmitting Non-ASCII Characters between PHP and MySQL

Viewing Character Set Variables

Non-ASCII Test Result Analysis

Fetching Non-ASCII Text from MySQL

Dr. Herong Yang, updated in 2007
Storing Non-ASCII Characters with Encoded Bytes