php - Get Chinese characters from MySQL -


i trying display chinese characters have saved in mysql database, saved under utf8_unicode_ci type. have seen several solutions on web, nothing works.

below connection file:

$conn = mysql_connect("localhost","root","password"); mysql_set_charset('utf8',$conn); mysql_query("set character set utf8 "); mysql_select_db("database"); 

below query:

mysql_query("set character_set_results=utf8", $conn);  $sql = mysql_query("select * webdata",$conn); 

but still shows ????. ideas?

how resolve...

when had similar issue firstly displayed encoding of text in php using

echo mb_detect_encoding ( $text ); 

it shows encoding of text coming query. showed me getting ascii mysql_query when chinese or russian characters in database.

the change made following addition after mysql_connect

mysql_set_charset('utf8'); 

my database utf8_unicode_ci collation , can see chinese characters.

so, if mb_detect_encoding giving utf8 text able show chinese characters.

the next step make sure pass browser has correct header...

header('content-type: text/html; charset=utf-8'); 

put above @ top of code in php make sure browser expecting encoding.

now should question, ideally should using pdo or mysqli rather mysql_connect method. in case equivalent procedural style commands are..

$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test'); mysqli_set_charset($link, "utf8"); 

where $link equivalent connection database.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -