Mysql_fetch_array returns non-Unicode text

I made a simple PHP page to get the POST data and get the sql request and then print the result. I am using the mysql_fetch_array function.

The code works fine, but the answer is non-Unicode text, and it returns something like this:

?????ABC?????

note that database sorting is UTF8 and the saved data is displayed correctly in phpMyAdmin. I even used this META tag on a php page, but it gives the same thing:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

Any idea ?!

+5
source share
3 answers

Add these lines of code before the first request:

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET SESSION collation_connection = 'utf8_unicode_ci'");

Or you can change mysql configuration to use utf8 by default. Check here what you need to do.

MySQL UTF-8 my.cnf?

UPDATE

mysql_query , mysqli :

$mysqli = new mysqli("localhost", "MYSQL_USER", "MYSQL_PASS", "MYSQL_DB");

$mysqli->query("SET NAMES 'utf8'"); 
$mysqli->query("SET CHARACTER SET utf8");  
$mysqli->query("SET SESSION collation_connection = 'utf8_unicode_ci'"); 
+12
mysql_set_charset('utf8', $link);

$link - , mysql_connect

+2

Try using mb_internal_encoding ("UTF-8"); for details http://php.net/manual/en/function.mb-internal-encoding.php

-1
source

All Articles