RSS

How to store UTF8 (indian language) data in mysql?

14 Sep

We assume we have a DataBase with table news, and a column named posts, which will save the news written in your website.We know that all major DataBase’s support UTF8. And we shall explore that feature.
Now we write a article in hindi, हेल्लो वर्ल्ड
If the UTF8 is not specified, you should see something like ?????? in ur DataBase otherwise you should see the hindi data. Clear? Now lets see the code given below:

First check for UTF8 compatibility with this query. If it supports you should see the output as “Character_set_system”| “UTF8″
SHOW VARIABLES LIKE ‘character_set_system’;
this will show the below result if support:

Full Texts
Variable_name    Value
character_set_system    utf8

Now that being checked, alter the table and just modify the column, which is ‘text’ in our above example and specify it as UTF8
ALTER TABLE news MODIFY text VARCHAR(200) CHARACTER SET UTF8;

Then execute following query before inserting into the table:

mysql_query(‘SET character_set_results=utf8’);
mysql_query(‘SET names=utf8’);
mysql_query(‘SET character_set_client=utf8’);
mysql_query(‘SET character_set_connection=utf8’);
mysql_query(‘SET collation_connection=utf8_general_ci’);

 
Now, try to insert the hindi value and save it. Query it and u should see the hindi text :)

 
2 Comments

Posted by on Sep 14, 2011 in Mysql, PHP

 

Tags: , , ,

2 responses to “How to store UTF8 (indian language) data in mysql?

  1. kiran

    Apr 21, 2012 at 11:28 am

    Could you please let me know same thing with java

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: