14 February 2011

How to write data in your database in Languages other than English?

Sometimes while using some website like Orkut ,  you might have seen a dictionary , using which you can translate your scrap into hindi language and send it to your friend.
Now a question might have struck into your mind, as all these scraps must be stored in some database which only allows only english language then how is it possible to store data in language other than English???
Well this post of mine will answer your question
Let us start , we all know that all major DB’s support UTF8. Using this feature, we will insert a word  हेल्लो that is in Hindi language in our database table.
For that let us create a table named post in database manish.
In order to create database and table you have to execute below mentioned queries first:-
Create database manish;
Create table post(name varchar(20));
Now if you try to insert this word in database without specifying UTF8 ,you should see some error like this:-
Incorrect string value: '\xE0\xA4\xB9\xE0\xA5\x87...'
Now in order to remove this error, you have to execute below mentioned sql query

Now, try to insert the hindi value and save it. You shud see the hindi text