4

i want to display unicode text in my site from mySql Database, im created table in unicode collation, but i can't display text by unicode text please refer bellow code i created.

<!Doctype html>
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{
    font-family:Latha;
}
</style>
</head>
<body>
<?php 
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbName = "mydb";

    //Create connection
    header("content-type: text/html; charset=UTF-8");  
    $conn = new mysqli($servername, $username, $password, $dbName);

    //Check connection
    if($conn->connect_error){
        die("Connection Failed : ". $conn->connect_error);


    }



    $sql="select txt, txt1,txt2 from dav";
    //mysqli_set_charset($sql, 'utf8');
    $result=$conn->query($sql);

    if($result->num_rows>0){
        //output data
        while ($row=$result->fetch_assoc()){
            echo "<div><p>" .$row["txt"]. "</p><p>" .$row["txt1"]. "</p><p>" . $row["txt2"]. "</p></div>";
        }

    }
    else{
        echo "No data found";
    }
    $conn->close();
?>

</body>
</html>

and output is like this

?????????? ????? ?????? ???????? ???????????? ????????? ??????.

?????????? ????? ?????? ???????? ???????????? ????????? ??????.

?????????? ????? ?????? ???????? ???????????? ????????? ??????.

but i want like this

வான்நின்று உலகம் வழங்கி வருதலால் தான்அமிழ்தம் என்றுணரற் பாற்று. வான்நின்று உலகம் வழங்கி வருதலால் தான்அமிழ்தம் என்றுணரற் பாற்று. வான்நின்று உலகம் வழங்கி வருதலால் தான்அமிழ்தம் என்றுணரற் பாற்று.

Please help me to fix this.

Sathishkumar
  • 419
  • 2
  • 8
  • 20

1 Answers1

1

I will fix this by adding bellow line

mysqli_set_charset( $conn, 'utf8');

its works fine.

Sathishkumar
  • 419
  • 2
  • 8
  • 20