Monday 6 January 2014

TAMIL in mysql == Storing and displaying unicode string (हिन्दी) using PHP and MySQL

FileName: tamil.php  Environment:WAMP

Thanks for REF:
http://stackoverflow.com/questions/1198701/storing-and-displaying-unicode-string-using-php-and-mysql

<!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">



<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">


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

mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_ci');

mysql_select_db('php',$con);

$nith = "CREATE TABLE IF NOT EXISTS `TAMILS` (
  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1";

if (!mysql_query($nith,$con))
{
  die('Error: ' . mysql_error());
}

$nithi = "INSERT INTO `TAMILS` VALUES ('இந்தியா நாட்டின் பக்கங்கள்5')";

if (!mysql_query($nithi,$con))
{
  die('Error: ' . mysql_error());
}

$result = mysql_query("SET NAMES utf8");//the main trick
$cmd = "select * from TAMILS";
$result = mysql_query($cmd);
while($myrow = mysql_fetch_row($result))
{
    echo ($myrow[0]);
echo '<br>';
}
?>
</body>
</html>

No comments:

Post a Comment