December 19, 2017
How to use Unicode for Chinese characters in ColdFusion and MySQL
Comments
(0)
December 19, 2017
How to use Unicode for Chinese characters in ColdFusion and MySQL
Software Architect and Web Developer
Newbie 3 posts
Followers: 0 people
(0)

Recently I worked in a project where special characters needed to be stored in a database, to be specific we needed to handle Chinese characters, to achieve this, some configurations need to be done in the ColdFusion Administrator regarding the Connection String setting and the database has to be created with certain parameters.

Creating the Database to use Unicode

create database meid default CHARACTER SET=utf8mb4 default COLLATE=utf8mb4_unicode_ci

As you can see the character set is utf8mb4, and the collate is utf8mb4_unicode_ci.  You may ask Why utf8mb4 instead of utf8?. Well the reason is that in MySQL at least, the set of characters handled by utf8 is shorter than utf8mb4.  If you already have your database in utf8 and need to switch to utf8mb4 or to read more about this check this article.

Note. All the tables you create after will keep the Unicode character set and collate that you specified when the database was created.

Now that the database is created the next step is:

Configure Data Source Name (DSN) to use Unicode.

Here I will explain how to configure an already added database.

  1. Open ColdFusion Administrator
  2. Locate DATA & SERVICES in the left menu
  3. Select Datasources to list the ones that are already added
  4. Click either on the name of the DSN in the “Data Source Name” column or in the Edit button in the “Actions” column Edit button
  5. Click on Show Advanced Settings
  6. In the “Connection String” box type
    allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
  7. Click on Submit

Configure DSN in CF Admin

That’s it, now you can use full Unicode in your application.

 

0 Comments
Add Comment