Accent in mysql select displaying question sign " "

Asked

Viewed 28,026 times

15

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

The files are all with correct accent in the database

My collation in the database is as: utf8_general_ci

I’m using the goal: utf-8

I’ll put my SELECT to see if you find any problem:

<?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 to over 500 places and I couldn’t solve the problem.

  • 2

    I’m in the same trouble right now!

  • How you migrated the data?

  • I backed up the database, created a new database and inserted sql

  • 2

    @Josimara Tenta echo utf8_encode($exibe['recadao_mensagem']);

  • That solved it, but why did this happen?

  • @Josimara Which IDE do you use? Should not be set to default UTF-8.

  • @Josimara put as an answer to your question.

Show 2 more comments

4 answers

18


Use the PHP function utf8_encode

Would look like this:

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

Note: Check that the IDE you use is set to UTF-8 default.

5

I had this same problem and I managed to solve it in the following way:

In my database connection file, 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');

Worked perfectly!

  • This solved for me, and you can still do in one run only: $Pdo->exec("SET NAMES 'utf8'; SET character_set_connection=utf8; SET character_set_client=utf8; SET character_set_results=utf8;");

1

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

0

mysqli_set_charset( $link, 'utf8');

or

$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);
  • Mysqli’s, with me it worked, thank you you helped me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.