Unicode characters become question marks after pasting into a database

When I insert any text written in unicode into the database, they become question marks. Database encoding is set to utf-8. What else could be wrong? When I check phpmyadmin, only question marks appear!

This is the code I use to connect to the database:

define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "root"); // set database user
define ("DB_PASS","password"); // set database password
define ("DB_NAME","name"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

mysql_set_charset('utf8',$link); 
mysql_query("SET CHARACTER SET utf8");
+5
source share
4 answers

Is the text you entered encoded in UTF-8? Or are your PHP files not UTF-8? Have you established a MySQL client connection with UTF-8?

If not, then this is probably the cause of the problem.

+3
source

, ? PHP, , phpmyadmin?

, , -, . :

header('Content-Type: text/html; charset=utf-8');
+2
 //first make sure your file produce utf-8 chars
 header('Content-Type: text/html; charset=utf-8');
 //make sure with your spelling
 //write 
 mysql_query("SET CHARSET utf8");     
 //instead of
 mysql_query("SET CHARACTER SET utf8");

 //for some reasons 
 mysql_query("SET CHARSET SET utf8");
 //works on some servers and for other servers not.i am not sure why?

 //try using mysql_set_charset("utf8"); only without mysql_query("SET CHARSET utf8");
 //for me i had the same issue with my server 
 //when i used mysql_set_charset("utf8"); only --> the problem solved
 //again make sure with your spelling and try again
0

, .. , :

mysql_query("SET CHARACTER SET utf8");
mysql_query("SET CHARSET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_unicode_ci'"); //This statement does the job!!! ;)

!

0

All Articles