Wednesday, May 6, 2009

Working with Bangla in php & mysql

for developing bangla unicode based application in php mysql follow the below steps.

————-

#1 . First make the database with CHARACTER utf8 and collation_connection =’utf8_general_ci’
#2 . Make the Tables with same configuration.
#3 . When u connect the database use following 2 lines just below the mysql_select_db()

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

#4 . Set the META-TAG as “Content-Type: text/html; charset=UTF-8″

Thats it D u r done.Here is a sample page what will show data from database

header(’Content-Type: text/html; charset=UTF-8′); //As its php page i dont need the meta-tag so i need to send a header .

mysql_connect(’localhost’,’xxxxx’,’xxxxxx’) or die(’Error In connection’);
mysql_select_db(’test’) or die(’Error In connection(DB)’);

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

$re = mysql_query(”SELECT * FROM test”) or die(’Query Problem’);
while($row = @mysql_fetch_assoc($re))
echo $row['name'].PHP_EOL;
?>

happy coding !!

1 comment:

  1. how can i do it in Zend. i mean i want to do it using zend db library.

    ReplyDelete

Followers