-1

Possible Duplicate:
how to select mysql query with foreign language?

I was unable to store characters like or beside text in mysql table ,but I change the collation to utf8-bin i can store them now but when i retrieve the text it displays ? character , is there any way to store these characters along with normal characters and retrieve them ? and does changing the collation affect the accuracy of searching on this text ?

Community
  • 1
  • 1
confucius
  • 13,127
  • 10
  • 47
  • 66
  • Many duplicates in the "related" column and in the search and on Google.... Also "can't retrieve" is not a good description of the problem. What exactly happens? – Pekka Feb 10 '12 at 13:40
  • Please see this, http://stackoverflow.com/questions/633762/special-characters-in-php-mysql – Milap Feb 10 '12 at 13:41
  • @Pekka when i retrieve the text it displays ? character . – confucius Feb 10 '12 at 14:07

3 Answers3

3

You need to make sure everything is in utf8:

  • The database
  • The database connection (something like $db->exec('SET CHARACTER SET utf8'); in PDO / PHP after making the connection)
  • Your php document if you are using php
  • Your html output
jeroen
  • 91,079
  • 21
  • 114
  • 132
0

I was having the same problem. You need to issue these queries before retrieving data from database.

mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");

And before echoing out the HTML to a web page, set the page charset to UTF-8.

header('Content-Type: text/html; charset=UTF-8');
Muhammad Abrar
  • 2,292
  • 1
  • 15
  • 13
-1

Try using a htmlentities() function. It will encode all applicable characters to html entities.

http://php.net/manual/en/function.htmlentities.php

Michal K.
  • 179
  • 2
  • 10
  • This is a terrible solution. This issue can be solved without resorting to stuff like this. – Pekka Feb 10 '12 at 13:52