Bangla insert and retrive using php & mysql

Lets see how to insert and retrive banlga font into the Mysql Database using PHP. We see the step for that.

  • First we Create a MySql database and tables which supports Bangla.
  • Insert Bangla value in the database .
  • Retrieve Bangla from the database.
    • Create Database to support Bangla :
      We give the database name bangla and it has 1 table which name is profile .We do that by phpMyadmin :

    • To create the database set character utf8_general_ci.
    • database_create.jpg

    • db_table1.jpg
    • db_field-1.jpg
      To keep things simple and easy to understand open the mysql command

    • mysql> set names ‘utf8′;
    • mysql> create database bangla character set utf8 collate utf8_general_ci;
    • mysql> use bangla;
    • mysql> create table profile (profile_name varchar(100) character set utf8 collate utf8_general_ci);

    Insert Bangla :
    So we create a database. Now we insert the value into the database. Insert Bangla Value in the database :
    We create a simple form :

    Input Form


    Then we will insert into the database :

    We create a coonection .

    1. $c = mysql_connect(“localhost”,”root”,””);
    2. mysql_select_db(‘bangla’) or die (mysql_error());
    //******These two line are used for Bangla Character *********/
    3. mysql_query(‘SET CHARACTER SET utf8’);
    4. mysql_query(“SET SESSION collation_connection =’utf8_general_ci'”) or die (mysql_error());

    You must add these two lines just after selecting the database, i.e mysql_select_db() function.
    mysql_query(’SET CHARACTER SET utf8′);
    mysql_query(”SET SESSION collation_connection =’utf8_general_ci’”);

    If you want to see more details then look at here (

    Now we will insert :
    mysql_query(“insert into profile values($_POST[“username])) or die (mysql_error());
    echo ‘saved into database’;
    echo ‘Not posted’;

    Now we check how the font stores into the database .
    Retrieve Bangla from the database:
    The display is as simple as retrieve other database.

    $res = mysql_query(“select * from profile”,$c);
    echo “
    Display resrult from database
    echo “————————“;
    while($row = mysql_fetch_array($res))
    echo $row[‘profile_name’] .’
    echo “————————“;

    Now one of the thing is how you write bangla in the webpage
    I fyou have no font please download the free software

    Avro software

    1. Good tutorial saidur bro – I am sure many web developers trying unicode bangla will find this useful.

      The following line seems like an “order” to mysql:

      mysql> use bangla;

      …banglai bolle “oi mysql, bangla use kor !”.


      • anisniit
      • November 25th, 2007

      I was finding for an easy instruction to start with unicode bangla. And this is the perfect tutorial for me.
      It really works.

      Thanks Saidur vai.

      • Jahedur Rahman
      • January 10th, 2008

      Waoo! Its a great thing. Thanks saidur. 🙂

      • Daniel
      • February 14th, 2008

      I am abslute a biginer of mysql. One of my colleagues made a database by mysql backend where some of the fields are in bangla like name, district etc. I have a copy of the folder which contains the data files. I wanted to retrieve those datas by importing the data in MS Access database. I can read all data, but I cannot read the bangla fields. I tried all your above mentioned procedures, but fail. I have programme called “SQL Manager for MySQL”, by that I can open the database. I have also installed “Avro Keyboard”. Can any one of you help me. Thanx.

    2. this tutorial is the best! i made alot of research about this thing and do alot of testing and it doesnt work. until i found this page! Am currently making a new free sms form website to mobile phone with different language, but am having hard time dealing on how to insert unicode to mysql database form php coding.. so thank you for this wonderfultutorial and it helps me alot to solve my problem! Thank and good job saidur!!!

      • Ranjan Yeng
      • February 18th, 2008

      Hi Saidur,
      I got lot of knowledge from your tutorial. I am trying “Bangla insert and Retrieve using JSP and MySQL”. I can retrieve Bangla but cannot insert bangla through jsp page. Can you please give me some idea.

      Thanks & Regards,
      Ranjan Y

    3. thanks saidur vai for visiting my blog, I have inspired for it.
      Shamim CSE-05

    4. Thanks everybody ,
      All of your comments encourage me to post more things here.Well if anybody want a sample code of that tutorial you can email me .

      when you convert into the MS Access , please check out the is the datatype is support the unicode.
      You may be checkout the links bellow to support unicode in MS Access

      @alvin of philippines:
      thanks alvin , it’s good to hear that you get benefit from this tutorial.

      @Ranjan Yeng :
      hi ranjon , to insert bangla in the database , there nothing difference in php and jsp. I think this code will be work in both place. However if you fix the issue you can tell us. Also if you want a sample code in php and mysql i can mail you .

      Thanks shamim bhai. Keep going on.

    5. very nice.

      • Enayet
      • April 15th, 2008

      1.i wanted to use bangla in a vb text editor, but i failed.
      i use avro 4.5.1 vartion . in my editor there are 2 bangla fonts but they are not matching with bijoy/national key i think u will help me about this.
      2.Another is database dealing with vb.

      • Qamrun Nisa
      • June 14th, 2008

      Hi, I have been working in PHP technology for one year. But its for the first time i m using a different language for inserting and retrieving data from database. From this tutorial i gain a lot of knowledge. Thnx a lot…..

      Warm Regards

      Qamrun Nisa

    6. Thanks Saidur Bro. I got solution for Bangla store in database. but I got some questions. at first i am telling, i am new in php mysql. so its silly ques but i need its answer.

      1. is it bangla unicode?
      2. i can put and get bangla from web browser but when i visit to my database i found many ascii code. but there is no bangla. is it normal or how can i get bangla in database too.

      reply me back plz.

    7. @Rony : Thanks to comments . I give the answers of your query below:

      1. Yes this is for bangla unicode. Well just set the collation in mysql as “utf8-general-ci” not treat as unicode. Please check out the link :

      2.Well you get the ascii value as you do not set the database as “utf8-general-ci” .. please follow the instruction as describe.

      Saidur Rahman

    8. Thanks for the nice tutorial. I can store data into MySql in bangla and also could retrieve successfully. But I am trying to develop a facebook application and there I tried to retrieve data from the same database I am using for my that site but I can’t see bangla in the facebook application. Any idea?

    9. I could solve the the problem. The solution is before retrieve data I have run the following two commands just before running the ‘SELECT’ query.

      mysql_query(’SET CHARACTER SET utf8′);
      mysql_query(”SET SESSION collation_connection =’utf8_general_ci’”);

      • Rownak
      • August 5th, 2008

      This indeed was very helpful.


    10. Nice work buddy

      • manir
      • September 19th, 2008

      i am from bangladesh. it a good tutor.
      i need upload image and display image and delete code in php without any database

      mail it my account

      • Indranil
      • September 30th, 2008

      I have two .doc / .rtf files having Bengali unicode characters. Is there any way to compare these two files using PHP, and after comparing a report will appear from where the user could find the differences.
      Please help me out. And if anybody gets the solution then please send it to my mail address.

      With regards,
      Indranil Basu

      • sislam
      • October 7th, 2008

      Hi thx for ur guideline. but i face problem . when i run insert query in database the stored value is


      how can i solve this problem . plz help me

    11. @sislam – This problem occurred may be you do not set the table as utf8_general_ci. Like you create a table profile. But when you create the table you do not set the table in utf8_general_ci. That’s why this problem occurred.

      • proshanto
      • November 20th, 2008

      thank u brother for ur great tast. with ur mamoth task i appreciate u.

      i am using WampServer2.0c and mysql4.01 for database. For database frontend i am using MySQL-Front 2.2. what to do to Bangla insert and retrive using php & mysql?

      pls solve tis and inform me as soon as possible.

      • Yegulew
      • November 22nd, 2008

      Dear Saidur Rahman Bijon,
      You have no idea how your tutorial helped me to achieve what I was searching for.
      I am from Africa and I was in need of creating a website by my own language. I used all your stelp and voila -> I got it.
      Thank you very much.
      I will post the problems that I might face and how I have solved them – since it will help any despite of the language.
      Once again thank you.

    12. In some cases ( specially in Zend Framework ) I saw that, data has inserted successfully as unicode but it loses encoding when retrieved.
      The following statement works fine for this situation:

      SET character_set_results=utf8

      For example, I use it in ZF as:

      $db = Zend_Db::factory($config->db);
      $db->query(‘SET character_set_results=utf8’);

      • proshanto
      • November 25th, 2008

      I am using
      WampServer2.0c where MySQL5.0.51b, PHP 5.2.6, Apache 2.2.8.

      I have two files named banglainput.php and bangla.php

      the code of banglainput.php is

      Untitled Document

      insert bangla

      and he code of bangla.php

      Untitled Document

      my ouput is “error to creating row”.

      where is my problem? is there anyone to help me?

    13. @Yegulew: happy to hear that you get benefited. Thanks everybody to share there solution and fellings.

      @Anis bhai : thanks to share Zend Framework issue. It will help lots of people. Nice job.

      @proshanto : at first thanks to post here. well this tutorial will work in any php based hosting. I think mysql will be 4.0 or greater. but i am not check this issue. It does not depend on the whether you used wampserver 2.0 or xampp server.
      Also i am not clear about the error you mention
      “error to creating row” . May be it causes to create the sql code .
      Use the MYSql Font and exicute the following code in the sql :

      set names ‘utf8′;
      create database bangla character set utf8 collate utf8_general_ci;
      use bangla;
      create table data (name varchar(100) character set utf8 collate utf8_general_ci);

      Well if you faced much more problem you can send me the your code


    14. Vaiy,
      it is really useful. Thanxxxxxxxx

      initially value were displaying as bunch of ???????????. when i have added these two lines (bellow), it works!

      mysql_query(‘SET CHARACTER SET utf8’);
      mysql_query(“SET SESSION collation_connection =’utf8_general_ci'”);

    15. o my’s really a good things…i am searching such types of things.

    16. Hey,

      Thanks Man. Nice post!

      Best of Luck!

    17. Nice bro,
      I tested with this code and worked fine in Myanmar Unicode.
      I use 3 files:


      // This is code for insert.htm

      Inserting Unicode

      //This is code for insert.php

      // This is code for retrieve.php

      $con = mysql_connect(“localhost”,”admin”,”admin”);
      if (!$con)
      die(‘Could not connect: ‘ . mysql_error());

      mysql_select_db(“mmuni”, $con);
      mysql_query(“SET character_set_results=utf8”, $con);
      $result = mysql_query(“SELECT * FROM tab”);

      echo ”


      while($row = mysql_fetch_array($result))
      echo “”;
      echo “” . $row[‘col’] . “”;
      echo “”;
      echo “”;


      // This is SQL command

      CREATE DATABASE ‘mmuni’ DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
      CREATE TABLE ‘tab’ (
      ‘col’ VARCHAR( 100 ) NOT NULL
      ) TYPE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;



    18. sorry,
      posting again

      Inserting Unicode

    19. i can’t post code here contact my mail

      • bappi
      • March 10th, 2009

      I am bappi. I want to read the bangla mysql can i get this from website .please informed to me.

    20. I was looking for Marathi localization settings and this worked for me perfectly. Thanks!

      • রকিব
      • May 20th, 2009

      হাই। আমি আপনার মত পিএইচপি প্রোগ্রামার হতে চাই। পরামর্শ দিন।

      • diganto
      • May 21st, 2009

      Hi Sahidur bro, thanks a lot for the absolute piece of writing that make life easier for who wants to work with unicode.

      • Rashed
      • August 12th, 2009

      i follow ur procedure. but failed. data is not inserted into db in bengla font. i found in db as ??? ????.
      can u explain it.


    21. Hi Dude,

      This is an excellent article. Helped me to kick start the first utf project. thanks a lot !!

    22. Thanks saidur bro 🙂 it is very helpful for me and other creative developers.

      • Arifur
      • September 4th, 2009

      I try same, what u describe above. But in my mysql database it insert আমি আপনার
      Why not i see the actual Bengla text in the database
      আমি আপনার
      Thanks for your post.

      • Arifur
      • September 4th, 2009

      Here it show the actual text in the previous post but but in my mysql database show & #2438 ; & #2478 ; & #2495 ; &#2438 ; &#2474 ; & #2472 ; & #2494 ; &#2480 ;


      • Ak Ashraf Chy
      • October 31st, 2009

      Hi, I’m Ak Ashraf Chy, I want learn PHP Program, so I want PHP tutorial in Bangla. How can I get it?

      • কাজ়ী আতাউল বারী
      • November 19th, 2009

      Great Tutorial

    23. Hi all
      I am Nazmul Huda

      I want to insert data from any form fields to mysql database.
      Please any one can help me.

      • hasnat
      • April 9th, 2010

      Hello Saidur Rahman Bijon,

      I hope you are doing good.Its great tutorial but that tutorial missing two things that i am face to implement in that project.

      I want to little introduce you abt me.I am hasnat and i am newbie in php.

      I appreciate your tutorial.Really it helps me, But i want to share that after all steps follow of your tutorial, i also set
      in head section

      But after that i do not get my desired result because data is not store in arbaic formart but that data store in unicode formart in such form


      So i googled and get the solution to fix it.

      In above tutorial you describe four points.

      That are

      1. $c = mysql_connect(“localhost”,”root”,””);
      2. mysql_select_db(‘bangla’) or die (mysql_error());
      //******These two line are used for Bangla Character *********/
      3. mysql_query(‘SET CHARACTER SET utf8′);
      4. mysql_query(“SET SESSION collation_connection =’utf8_general_ci’”) or die (mysql_error());

      Then i add only one line that is

      header(“Content-Type: text/html; charset=utf-8”);

      Then all the problem fix that i face to insert data in db after put that line after four point.

      So sucessfully insert data in arbaic format in mysql.

      By the Way Thanks

      Highly Appreciated.
      Hasnat Ahmad Hussny

      • hasnat
      • April 9th, 2010

      oops im my comment box my some statements are ghosted

      Sorry guys

      in head section

      meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″

      and in unicode format like as


      That statements are ghosted…

      • hasnat
      • April 9th, 2010

      oops again and in unicode format like as

      “statement in that qoutes are parsed in arbaic formart”

      sorry guys again i hope you understand what i say to you in my comment box.

      • jewel
      • May 4th, 2010

      Will I able to execute all SQL operation including arithmatic or logical operation on the বাংলা value of table fields? Will there any change in the table fields type ( data type )?

      I want to make myself clear about what goes on in the ‘memory’ for data presentation when we use unicode instead of ASCII code.

      Difference between memory representations of ASCII value and uni code value.

      please, response if any one know.

      • jewel
      • May 4th, 2010

      সমস্ত বাংলা শব্দ গুলো Database এর Table এ VARCHAR টাইপ এ পাই কিন্তু
      INT অথবা FLOAT টাইপ এ পাচ্ছি না। Field টাইপ VARCHAR করলে ১,২,৩,……… অথবা ২৫.২৬, ৯২.২৫ ……… টাইপের data পাওয়া যায় কিন্তু
      INT অথবা FLOAT টাইপে পাওয়া যায় না কেন?

      • jewel
      • May 5th, 2010

      char ch[]=”This is an ASCII string in C”;
      char ch[]=”ইহা একটি বাংলা ইউনিকোড স্ট্রিং”;
      এই দুটি statement কে একই ভাবে string functions দিয়ে manipulation করা কি সম্ভব? কেন?

      • jewel
      • May 5th, 2010

      কার যদি জানা থাকে, উপরের questions গুলোর answer দিন।

    24. Vai PHP dia akta website create korte chai . Step by step bornona dilay khub upokrito hotam.

      • azgar
      • July 12th, 2010

      nice code.

      • স্বপ্নডীঙা
      • October 5th, 2010

      mysql> set names ‘utf8′;
      mysql> create database bangla character set utf8 collate utf8_general_ci;
      mysql> use bangla;
      mysql> create table profile (profile_name varchar(100) character set utf8 collate utf8_general_ci);

      ভাই এইটা বুঝি নাই। একটু বলেন।

      • স্বপ্নডীঙা
      • October 6th, 2010

      আমি ডেটাবেজ এ বাংলা দেখতে পাই। কিন্তু যখন সিলেক্ট করি তখন ব্রাউজারে নিন্মের ভুলটি দেখায়ঃ কিন্তু এটা দিয়ে ইংলিশ ঠিক দেখায়
      Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\my site\reg\sopnodinga_dictionary\select_table.php on line 36
      Word Meaning Incumbency Sentence

      বিঃদ্রঃ আমার [select.php]

      Search Word

      আপনার শব্দটি খুজুন:

      বাংলা থেকে ইংরেজী
      ইংরেজী থেকে বাংলা
      বাংলা থেকে বাংলা
      ইংরেজী থেকে ইংরেজী


      আমার [select_table.php]


      $con = mysql_connect("localhost","root","");
      if (!$con)
      die('Could not connect: ' . mysql_error());

      mysql_select_db("Dictionary", $con);
      mysql_query('SET CHARACTER SET utf8');

      mysql_query("SET SESSION collation_connection ='utf8_general_ci' ");

      //select data frob db
      $select = mysql_query("SELECT * FROM $_POST[search]",$con);

      echo "


      while($row = mysql_fetch_array($select))

      echo “”;
      echo “” . $row[‘Word’] . “”;
      echo “” . $row[‘Meaning’] . “”;
      echo “” . $row[‘Incumbency’] . “”;
      echo “” . $row[‘Sentence’] . “”;
      echo “”;
      echo “”;


      আমার ডেটাবেজের নাম ও টেবিলের নাম যথাক্রমে [Dictionary][(English_to_bangla)(এতে ৪টি field রয়েছে, Word,Meaning,Incumbency,Sentence)]

      এর কোথায় ভুল আছে please একটু দয়া করে জানাবেন
      আমার email address []

      • mel
      • November 10th, 2010

      hey thanx found it very useful

      • বাসার
      • February 8th, 2011

      ur tutorial is very helpful for me brother.
      Thank u.


      • বাসার
      • February 10th, 2011

      if i use ajax to submit Bangla data it becomes

      please give me the solution.


        • elias
        • March 4th, 2011

        add the headermeta http-equiv=”Content-Type” content=”text/html; charset=utf-8″

    25. @ thanks elias

    26. fasdfsdfsd

    27. Nice post bro, It helped me lot

    28. I want to be a php&mysql programmer. Please give me tutorial.

    29. Thank you…very much…

    30. Many airlines service capital and resort cities in Southeast Asia,
      but a majority of are incredibly cheap while others are wildly
      expensive. Globalization gets to be more of a reality every day, but this does
      not mean the cultures of the world need morph into one huge conglomerate such as the puddingstones of New England.
      If you buy the popular #1 Size of Kratom capsules, begin which has a dosage of 1-4 pills.
      Since Asia China pharmaceutical market consultant has the ability to leverage external and internal resources, the business objectives are met.

    31. Hello there! Thhis popst could not be written much better!
      Reading through this article reminds me of my previous roommate!
      He continually kept talking about this. I most certainly will forwqard
      this popst to him. Fairly certain he’ll have a great read.
      Many thanks ffor sharing!

      • kaniz
      • December 19th, 2014

      helpful. Thank you 🙂

    32. anyone one help me to buil english to bangla dictionary in php mysql

    33. I got this website from my friend who shared with me regarding
      this website and now this time I am visiting this website and reading very informative posts here.

    1. No trackbacks yet.

    Leave a Reply

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

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

    Google+ photo

    You are commenting using your Google+ 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 )

    Connecting to %s

    %d bloggers like this: