Storing Non-ASCII Characters in Database

This section describes how to store non-ASCII characters in MySQL database using different character set settings set column, table or database level.

MySQL can store non-ASCII characters in database in a number of encodings, MySQL call them character sets:

+----------+-----------------------------+
| Charset  | Description                 |
+----------+-----------------------------+
| big5     | Big5 Traditional Chinese    |
| dec8     | DEC West European           |
| cp850    | DOS West European           |
| hp8      | HP West European            |
| koi8r    | KOI8-R Relcom Russian       |
| latin1   | ISO 8859-1 West European    |
| latin2   | ISO 8859-2 Central European |
| swe7     | 7bit Swedish                |
| ascii    | US ASCII                    |
| ujis     | EUC-JP Japanese             |
| sjis     | Shift-JIS Japanese          |
| cp1251   | Windows Cyrillic            |
| hebrew   | ISO 8859-8 Hebrew           |
| tis620   | TIS620 Thai                 |
| euckr    | EUC-KR Korean               |
| koi8u    | KOI8-U Ukrainian            |
| gb2312   | GB2312 Simplified Chinese   |
| greek    | ISO 8859-7 Greek            |
| cp1250   | Windows Central European    |
| gbk      | GBK Simplified Chinese      |
| latin5   | ISO 8859-9 Turkish          |
| armscii8 | ARMSCII-8 Armenian          |
| utf8     | UTF-8 Unicode               |
| ucs2     | UCS-2 Unicode               |
| cp866    | DOS Russian                 |
| keybcs2  | DOS Kamenicky Czech-Slovak  |
| macce    | Mac Central European        |
| macroman | Mac West European           |
| cp852    | DOS Central European        |
| latin7   | ISO 8859-13 Baltic          |
| cp1256   | Windows Arabic              |
| cp1257   | Windows Baltic              |
| binary   | Binary pseudo charset       |
| geostd8  | GEOSTD8 Georgian            |
+----------+-----------------------------+

To store non-ASCII characters in a database column, you need to define that column with a specific character set. You can specify a character set at 3 levels: database, table, and column. For example:

   CREATE DATABASE db_name CHARACTER SET utf8
   CREATE TABLE tbl_name (...) CHARACTER SET utf8
   CREATE TABLE tbl_name (col_name CHAR(80) CHARACTER SET utf8, ...)

Last update: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

Managing Non-ASCII Character Strings with MySQL Servers

Storing Non-ASCII Characters in Database

 Transmitting Non-ASCII Characters with Database

 MySqlUnicode.php - MySQL Unicode UTF-8 Encoding Example

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials

 References

 PDF Printing Version