Select mysql accent showing question mark " " [duplicate]

14

Today I migrated my site to the hostgator and this problem happened, the accents are all with some characters

The files are all with correct accent in the database

My collation in the database is like: utf8_general_ci

I'm using meta: utf-8

I'll put my select to see if you have any problems:

<?php 
$sql = mysql_query ("SELECT * FROM recadao ORDER BY id DESC LIMIT 3");
while ($exibe = mysql_fetch_assoc($sql)){
?>

<?php echo $exibe['recadao_mensagem']; ?>

<?php } ?>

I've been in more than 500 places and I could not solve the problem.

    
asked by anonymous 26.04.2014 / 00:23

4 answers

15

Use the PHP function utf8_encode

It would look like this:

echo utf8_encode($exibe['recadao_mensagem']);

Note: Make sure that the IDE you are using is set to UTF-8.

    
26.04.2014 / 00:40
4

I had this same problem and managed to resolve it as follows:

In my connection file with the bank, I put the code below:

mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');

It worked perfectly!

    
14.07.2015 / 14:20
1

Assuming your old DB was also set to utf8_general_ci , then the error might be in backup. Verify that the backup files were also saved as UTF-8 .

    
26.04.2014 / 00:43
0
mysqli_set_charset( $link, 'utf8');

or

$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);
    
10.04.2017 / 02:59