Using Bangla in MySQL Database

On May 18, 2008, in Uncategorized, by admin

Recently I’m working on bangla. The part of this work I learn how to insert & retrieve bangla into MYSQL database using PHP.
Now I’ll discuss the whole process of insert & retrieve bangla into MYSQL database.

It is very easy, we all know how insert & retrieve data from database. Bangla font inserting is almost same. Only two queries are extra needed.

First we have created a database & table using MYSQL to insert bangla.
Now open the mysql command prompt & create database named bangla, & create a table named data.
Now write those command:

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

Insert Bngla into database:
So we create database & table for where we insert bangla font. Now we have to create a simple form where we input bangla word.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<form method=”get” action=”bangla.php”>
insert bangla<input name=”name” type=”text” />
<br />
<br />
<input type=”submit” value=”insert bangla” />
</form>
<body>
</body>
</html>

Now just copy the code & save as banglainput.php.

Now insert bangla font into database.

<?php

$cnt = mysql_connect(“localhost”,”root”) or die (“could not localhost”);

mysql_select_db(‘bangla’,$cnt);
//********This Two Lines for bangla*********//
mysql_query(‘SET CHARACTER SET utf8′);mysql_query(“SET SESSION collation_connection =’utf8_general_ci’”) or die (mysql_error());
//*******************************************//

$sql = mysql_query(“insert into data values(‘$_GET[name]‘)”) or die(“error to creating row”);

$results = mysql_query(“select *from data”,$cnt);

echo “the results is “;

while($row = mysql_fetch_array($results))

{

echo $row['name'] .’ ‘;

}

?>

Now copy these code and save as bangle.php.

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’”);


Its very easy Just Copy those code paste and run. Ooo the most importnt thing, you need a unicode for insert & retrive. i use avro unicode. So you must download avro unicode.

this tutorial is referenced by saidur vai.

Tagged with:  

23 Responses to “Using Bangla in MySQL Database”

  1. ranacse05 says:

    nice post buddy :D

  2. shamim says:

    very good job…..

  3. Dear Saeed,
    Thanks for this post, try to do more practice and more post.
    Regards,
    Iqbal Hossain
    http://www.SabaSafa.com

  4. Kushan Sasanka says:

    Dear Friend,
    Thank you very much for the script regarding utf8.
    I didn’t try it for Bangla. I just tried for Sinhala.
    Thats my language in sri lanka.
    And the insert operation was successful.
    Thank you very much.

    keep it up… keep going…

    Bye..
    - Kushan -
    from Sri Lanka

  5. Kushan Sasanka says:

    මම හොය හොයා හි‍ටපු නියම ස්ක්‍රිප්ට් එක

  6. Mr Zack says:

    <?

    if ($sub == “ok”) {

    if (empty($name))
    echo “Form is incomplete!”;

    else {

    $link=db_connect(“china”, $PHP_SELF);
    mysql_query(‘SET CHARACTER SET utf8′);
    mysql_query(“SET SESSION collation_connection=’utf8_general_ci’”);

    $Sql = “INSERT INTO CloseOut (hotelname, hotel_id, closed_from, closed_to, reason, detail)
    values (‘$_POST[name]‘,’$_POST[hotel_id]‘,’$_POST[date_from]‘,’$_POST[date_to]‘,’$_POST[reason]‘,’$_POST[detail]‘)”;

    echo “$Sql”;
    $result = mysql_query($Sql);
    if (!$result)
    echo “Error performing query!”;
    else
    echo “New package has been successfully added.”;
    }

    mysql_close($link);
    }

    ?>

  7. bopdilly says:

    Excellent site! I wish the owner to develop and please all! http://sex-free-online.ru/map.html

  8. proshanto says:

    thank for ur kind cooperation.

    i have ecuted these above codes. but i face the message “error to creating row”

    wha can i do now.

  9. Saeed says:

    i think, you can not create database and table properly. to create database and table you need to follow those command
    mysql> set names ‘utf8′;
    mysql> create database bangla character set utf8 collate utf8_general_ci;
    mysql> use bangla;
    mysql> create table data (name varchar(100) character set utf8 collate utf8_general_ci);

    if you follow those command properly then plz check you using variable name. correct your variable name with your own server configuretaion.

    i think now you solve your problem.

    thank you

  10. proshanto says:

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

    My database name is psqlpro, table name is psqlpro1 and field name is p1. and there are many tables in my database.
    I have two files named banglainput.php and bangla.php to insert and retrive bangla

    the code of banglainput.php is

    Untitled Document

    insert bangla

    and the code of bangla.php

    Untitled Document

    my ouput is “error to creating row”.

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

  11. Saeed says:

    there are everything is allright. donot panic. its very simple.
    your problem solve is here

    write those command in mysql:

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

    then paste my code to your IDE and run. i think it will be solve.
    if yet not solve your problem then i invite you on yahoo. connact me asap.
    i will solve it.

  12. sandrar says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  13. krishna says:

    Good Concept, Saeed
    And I thing This is enough for Understanding

  14. bokul says:

    thanks.

  15. Srabon says:

    কাজে লাগলো … আপনাকে ধন্যবাদ :)

  16. Hi,
    This tutorial is very helpful, when i insert any data to mysql database it is show in phpmyadmin,
    but no bengali is shown in my php page.
    I could not understand about this problem.
    when i write something in mysql table then show in my php page is

    খুলনা ভিউ

  17. Dewsworld says:

    Hi!
    In my PHPmyadmin bangla text are stored like খুলনা ভিà,
    But in rendering everything’s ok except the bangla in tags .
    Any idea what foolish stuff I made?

  18. Nilachal says:

    Thanks a lot. very good stuff

  19. Shakil says:

    Heres a problem that.. If you try to post long Bengali paragraphs like:

    আপনারা ইতিমধ্যেই জেনেছেন, ডয়চে ভেলে সেরা ব্লগ অনুসন্ধান প্রতিযোগিতা ২০১১ শুরু হয়েছে৷ আগামী ১১ই মার্চ পর্যন্ত এই প্রতিযোগিতায় ব্লগ জমা দেওয়া যাবে। বাংলা ভাষাসহ এই প্রতিযোগিতায় অংশ নেবে এগারোটি ভাষা। আর মাত্র চার দিন পরই শুরু হচ্ছে ‘ডয়চে ভেলে’র আয়োজনে আন্তর্জাতিক ব্লগ অনুসন্ধান প্রতিযোগিতা ‘

    try this to post i will say error….

    Have you any solution of it….

    Thanks

Leave a Reply

Free WordPress Themes

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...