Monday, July 13, 2009

SQL Server with Unicode / Khmer Unicode characters

To be notice MS SQL supports only UCS-2 encoding so do not have encoding with UTF-8 as we expected as MySQL or some other database server as well. This means that you can't use UTF-8 character encoding with Microsoft SQL Server:

Here after I type Khmer Unicode and execute the query, I got question marks instead of characters:

So if you need to store national characters in Microsoft SQL Server - please consider using a national character encoding (U+1780 to U+17FF in Unicode/ISO10646 for Khmer Unicode characters, for example). Change data types:
  • varchar to nvarchar
  • text to ntext
  • char to nchar
Here is the example since I created a table and insert data:
1. Create database (mtr_db) as normally (default setting)

2. Create table (tblunicode) with two fields (id/name) but
name - data type nvarchar(MAX)


3. Insert Khmer Unicode and execute we got it as we typed!
Good luck!

10 comments:

  1. hi, i can insert into database but the character still show the question mark(??????), and could you please to tell what is my mistake.

    thank

    ReplyDelete
  2. how to search string in khmer unicode from Ms SQl

    ReplyDelete
  3. this solution can not help me! i still got ???????????? in my table

    ReplyDelete
  4. TRY THIS:

    EXAMPLE: INSERT INTO tUSER(UserName) VALUES(N'កម្ពុជា')

    HOPE THIS HELPFUL

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete
  5. I connect to mysql by php like this, and it work perfect for me:
    $host = "localhost";

    $user = "root";//Your mysql user
    $pass = "";//Your mysql password
    $db = "book_songs";////Your mysql database name

    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

    mysql_query("SET character_set_results=utf8",$connection);
    mb_language('uni');
    mb_internal_encoding('UTF-8');

    mysql_select_db($db, $connection) or die ("Unable to select database!");
    mysql_query("set names 'utf8'",$connection);

    Hope this can help you

    ReplyDelete
  6. https://www.youtube.com/watch?v=5D_ElHGZ-i8

    i hop this video can help u

    ReplyDelete

Note: Only a member of this blog may post a comment.