php, mysql & unicode

It all started when I wanted to make a website in Bangla. The best way was to use unicode. First of all, I had to install because the older versions did not support unicode or it supported in a very funny way. Use php 4.3.8

To keep things simple and easy to understand open the mysql command prompt.

mysql> set names ‘utf8’;

mysql> create database baka character set utf8 collate utf8_general_ci;

mysql> use baka;

mysql> create table haka (mala varchar(100) character set utf8 collate utf8_general_ci);

The database is created and one table has also been created.

Now for the php part. Create a file called index.php and write the following in it

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<TITLE> Unicode </TITLE>
<META NAME=”Generator” CONTENT=”Microsoft FrontPage 5.0″>
<meta http-equiv=”Content-Language” content=”bn”>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ >

$c = mysql_connect(“localhost”,”root”,”iit123″);

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

 mysql_query(“insert into haka values(‘”.$_POST[“username”].”‘)”);
 echo “saved”;
 echo mysql_error(); 
 echo “not posted”;

$d = mysql_query(“select * from haka”,$c);
while($x = mysql_fetch_array($d))
 echo $x[“mala”].”<br>”;
<form action=”index.php” name=”frm” method=”post”>
 <input type=”text” name=”username” size=”20″>
 <input type=”submit” value=”Login” name=”btnLogin”>

Thats all. Now you can see and save unicode in php and mysql.


4 thoughts on “php, mysql & unicode

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s