· 8 years ago · May 22, 2018, 03:54 AM
1<html>
2 <head>
3 <title>Hindi</title></head>
4 <body>
5 <?php
6 include("connection.php"); //simple connection setting
7 $result = mysql_query("SET NAMES utf8"); //the main trick
8 $cmd = "select * from hindi";
9 $result = mysql_query($cmd);
10 while ($myrow = mysql_fetch_row($result))
11 {
12 echo ($myrow[0]);
13 }
14 ?>
15 </body>
16</html>
17
18CREATE TABLE `hindi` (
19 `data` varchar(1000) character set utf8 collate utf8_bin default NULL
20) ENGINE=InnoDB DEFAULT CHARSET=latin1;
21
22INSERT INTO `hindi` VALUES ('सूरà¥à¤¯à¥‹à¤¦à¤¯');
23
24<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
25
26header( 'Content-Type: text/html; charset=utf-8' );
27
28<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
29
30
31<?php
32$con = mysql_connect("localhost","root","");
33if (!$con)
34 {
35 die('Could not connect: ' . mysql_error());
36 }
37
38mysql_query('SET character_set_results=utf8');
39mysql_query('SET names=utf8');
40mysql_query('SET character_set_client=utf8');
41mysql_query('SET character_set_connection=utf8');
42mysql_query('SET character_set_results=utf8');
43mysql_query('SET collation_connection=utf8_general_ci');
44
45mysql_select_db('onlinetest',$con);
46
47$nith = "CREATE TABLE IF NOT EXISTS `TAMIL` (
48 `data` varchar(1000) character set utf8 collate utf8_bin default NULL
49) ENGINE=InnoDB DEFAULT CHARSET=latin1";
50
51if (!mysql_query($nith,$con))
52{
53 die('Error: ' . mysql_error());
54}
55
56$nithi = "INSERT INTO `TAMIL` VALUES ('இநà¯à®¤à®¿à®¯à®¾ நாடà¯à®Ÿà®¿à®©à¯ பகà¯à®•à®™à¯à®•ளà¯')";
57
58if (!mysql_query($nithi,$con))
59{
60 die('Error: ' . mysql_error());
61}
62
63$result = mysql_query("SET NAMES utf8");//the main trick
64$cmd = "select * from TAMIL";
65$result = mysql_query($cmd);
66while($myrow = mysql_fetch_row($result))
67{
68 echo ($myrow[0]);
69}
70?>
71</body>
72</html>