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 :
- To create the database set character utf8_general_ci.
We give the database name bangla and it has 1 table which name is profile .We do that by phpMyadmin :
- 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);
prompt.
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 (http://hasin.wordpress.com/2006/07/18/storing-bangla-unicode-text-in-mysql-database/)
Now we will insert :
if(isset($_POST))
{
mysql_query(“insert into profile values($_POST[“username])) or die (mysql_error());
echo ‘saved into database’;
}
else
{
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
http://www.omicronlab.com/avro-keyboard-download.html
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 !”.
🙂
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.
Waoo! Its a great thing. Thanks saidur. 🙂
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.
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!!!
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
thanks saidur vai for visiting my blog, I have inspired for it.
Shamim CSE-05
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 .
@Daniel:
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
http://vietunicode.sourceforge.net/howto/convertaccessdb.html
http://www.kofler.cc/mysql/mssql2mysql.html
@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 .
@shamimcse05:
Thanks shamim bhai. Keep going on.
very nice.
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 layout.so i think u will help me about this.
2.Another is database dealing with vb.
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
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.
@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 : http://hasin.wordpress.com/2006/07/18/storing-bangla-unicode-text-in-mysql-database/
2.Well you get the ascii value as you do not set the database as “utf8-general-ci” .. please follow the instruction as describe.
Thanks
Saidur Rahman
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?
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’”);
This indeed was very helpful.
Thanks
Nice work buddy
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
Hi,
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
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
@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.
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.
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.
Yegulew.
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’);
Zend_Db_Table::setDefaultAdapter($db);
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?
@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 bijon_php@yahoo.com
thanks
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'”);
o my god.it’s really a good things…i am searching such types of things.
thanks
Hey,
Thanks Man. Nice post!
Best of Luck!
-Amit
Nice bro,
I tested with this code and worked fine in Myanmar Unicode.
I use 3 files:
insert.htm
insert.php
retrieve.php
=================
// This is code for insert.htm
Inserting Unicode
=======================
//This is code for insert.php
=============================
// This is code for retrieve.php
<?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 ”
Record
“;
while($row = mysql_fetch_array($result))
{
echo “”;
echo “” . $row[‘col’] . “”;
echo “”;
}
echo “”;
mysql_close($con);
?>
======================
// 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;
😛
phoenyo
sorry,
posting again
Inserting Unicode
i can’t post code here contact my mail phoenyo@gmail.com
I am bappi. I want to read the bangla mysql book.how can i get this from website .please informed to me.
I was looking for Marathi localization settings and this worked for me perfectly. Thanks!
হাই। আমি আপনার মত পিএইচপি প্রোগ্রামার হতে চাই। পরামর্শ দিন।
Hi Sahidur bro, thanks a lot for the absolute piece of writing that make life easier for who wants to work with unicode.
Hi,
i follow ur procedure. but failed. data is not inserted into db in bengla font. i found in db as ??? ????.
can u explain it.
Rahed
Hi Dude,
This is an excellent article. Helped me to kick start the first utf project. thanks a lot !!
Thanks saidur bro 🙂 it is very helpful for me and other creative developers.
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.
Regard
ARIFUR RAHMAN
Here it show the actual text in the previous post but but in my mysql database show & #2438 ; & #2478 ; & #2495 ; আ ; প ; & #2472 ; & #2494 ; র ;
Regard
ARIFUR RAHMAN
Hi, I’m Ak Ashraf Chy, I want learn PHP Program, so I want PHP tutorial in Bangla. How can I get it?
Great Tutorial
Hi all
I am Nazmul Huda
I want to insert data from any form fields to mysql database.
Please any one can help me.
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
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…
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.
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.
সমস্ত বাংলা শব্দ গুলো Database এর Table এ VARCHAR টাইপ এ পাই কিন্তু
INT অথবা FLOAT টাইপ এ পাচ্ছি না। Field টাইপ VARCHAR করলে ১,২,৩,……… অথবা ২৫.২৬, ৯২.২৫ ……… টাইপের data পাওয়া যায় কিন্তু
INT অথবা FLOAT টাইপে পাওয়া যায় না কেন?
char ch[]=”This is an ASCII string in C”;
char ch[]=”ইহা একটি বাংলা ইউনিকোড স্ট্রিং”;
এই দুটি statement কে একই ভাবে string functions দিয়ে manipulation করা কি সম্ভব? কেন?
কার যদি জানা থাকে, উপরের questions গুলোর answer দিন।
Vai PHP dia akta website create korte chai . Step by step bornona dilay khub upokrito hotam.
nice code.
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);
ভাই এইটা বুঝি নাই। একটু বলেন।
আমি ডেটাবেজ এ বাংলা দেখতে পাই। কিন্তু যখন সিলেক্ট করি তখন ব্রাউজারে নিন্মের ভুলটি দেখায়ঃ কিন্তু এটা দিয়ে ইংলিশ ঠিক দেখায়
———————————————-
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]
———————————————————–
<?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 "
Word
Meaning
Incumbency
Sentence
“;
while($row = mysql_fetch_array($select))
{
echo “”;
echo “” . $row[‘Word’] . “”;
echo “” . $row[‘Meaning’] . “”;
echo “” . $row[‘Incumbency’] . “”;
echo “” . $row[‘Sentence’] . “”;
echo “”;
}
echo “”;
mysql_close($con)
?>
————————————————————
আমার ডেটাবেজের নাম ও টেবিলের নাম যথাক্রমে [Dictionary][(English_to_bangla)(এতে ৪টি field রয়েছে, Word,Meaning,Incumbency,Sentence)]
এর কোথায় ভুল আছে please একটু দয়া করে জানাবেন
আমার email address [sopnodinga@yahoo.com]
hey thanx found it very useful
ur tutorial is very helpful for me brother.
Thank u.
Bashar
if i use ajax to submit Bangla data it becomes
চিকিৎসা
please give me the solution.
Bashar
add the headermeta http-equiv=”Content-Type” content=”text/html; charset=utf-8″
@ thanks elias
fasdfsdfsd
Nice post bro, It helped me lot
I want to be a php&mysql programmer. Please give me tutorial.
Thank you…very much…
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.
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!
helpful. Thank you 🙂
anyone one help me to buil english to bangla dictionary in php mysql
aye grateful iast adopted http://ycblrs.cn/home.php?mod=space&uid=50033 unfair taste wrists
returns soul offensive technically bandit halt http://www.italianfansofdepp.com/gallery/profile.php?uid=14360 mainland credit midst crylng
organs third chain http://swanson.f2s.com/smf/index.php?action=profile;u=26335 loved terry dear