tags:

views:

251

answers:

4
table 'abc' data :

tid    title

  1      வெள்ளிக்கிழமை ஐ.

  2      கோலாகல தொடக்க 


$sql=mysql_query("select title from abd where tid='1'");

$row=mysql_fetch_array($sql);

$title = $row['title'];

echo $title;

OutPut displaying like this:

????????????????

But I want to display

வெள்ளிக்கிழமை ஐ.

Solution

<?php
    mysql_query ("set character_set_results='utf8'");   

    $sql=mysql_query("select title from abd where tid='1'");

    $row=mysql_fetch_array($sql);

    $title = $row['title'];

    echo $title;

?>
A: 

First you need to convert your mysql data format to utf-8, see this great article by oreilly:

.

Turning MySQL data to UTF-8

.

After that make sure that your page's encoding type is utf-8:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Sarfraz
@Srinivas Tamada: The final answer you chose did the same thing what has been told in the oreily article i posted the link above. Anyways, it is good that you found the solution. Thanks..
Sarfraz
+3  A: 

Try to make sure the browser recognizes the page as Unicode.

Generally, this can be done by having your server send the right Content-type HTTP header, that includes the charset you're using.


For instance, something like this should work :

header('Content-type: text/html; charset=UTF-8');
echo "வெள்ளிக்கிழமை ஐ";


If this works, and your dynamically generated page still doesn't :

  • make sure your data in your MySQL database is in UTF-8 too
    • this can be set for each table, or even columns, in MySQL
  • and make sure you are connecting to it using UTF-8.

Basically, all your application should use the same encoding :

  • PHP files,
  • Database
  • HTTP server
Pascal MARTIN
+8  A: 

Try to set charachter encoding after mysql_connect function like this:

 mysql_query ("set character_set_client='utf8'"); 
 mysql_query ("set character_set_results='utf8'"); 

 mysql_query ("set collation_connection='utf8_general_ci'"); 
antyrat
Antyrat Thank You ! working now...
Srinivas Tamada
Thanks for this, I'm rapidly approaching the same problem. +1
Tim Post
A: 

execute query

SET NAMES 'utf8'

right after connecting to database

Silver Light