Stress problem PHP and Mysql

Asked

Viewed 1,947 times

-2

I have a question regarding accentuation, specifically the return of Ç. My bank has the collation latin1_swedish_ci, I’m using the HTML tags:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <html lang="pt-BR">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

And in the bank is recorded correctly Ç and accents as below:

But when it comes to displaying the data, it appears that way:

PHP displays this way (in the 3rd line I did a test that did not work):

foreach ($saidas as $saida) { ?>
   <tr>
   <td><?php echo $saida['reserva'] ?></td>
   <td><?php echo $saida['motorista'] ?></td>
   <td><?php header("Content-Type: text/html; charset=ISO-8859-1", true); echo $saida['setor'] ?></td>
   <td><?php echo $saida['email'] ?></td>
   <td><?php echo $saida['veiculo'] ?></td>
   <td><?php echo $saida['destino'] ?></td>
   <td><?php echo $saida['data'] ?></td>
   <td><?php echo $saida['saida'] ?></td>
   <td><?php echo $saida['retorno'] ?></td>
   <td><?php echo $saida['retorno_real'] ?></td>
   </tr>

<?

Any suggestions?

  • 2

    test with the collation to utf8_general_ci

  • Rafael, I changed the collation of the bank and the tables but it didn’t work either.

  • @Are you using any framework or are you using pure PHP? and remember, when you make the changes in the collation the data that is already in the database has not changed, only the new data will be validated with the new rule.

  • Because it’s Diego.. You’ll find dozens of different tips and you’ll try them all. Most unsuccessfully and without knowing what you’re doing. And still running the risk of corrupting the data. The right thing to do is to start with diagnostics and try to understand how to analyze the current environment situation. Never apply a remedy without making a proper diagnosis. Don’t expect a magic solution because you don’t have one. But if you want, you can keep trying your luck. Soon someone will point out the utf8_decode() at random. That’s where the magic starts to happen. rsrs

  • This question was the subject of this debate: http://meta.pt.stackoverflow.com/q/4640/132

2 answers

4


I resolved so:

<td><?php echo utf8_decode($saida['setor']) ?></td>
  • Right, but that’s for items that come from the bank or goes for any special word?

  • @That goes for exiting the bank. For the HTML itself, in the header you have to declare: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

  • Okay, can you analyze my question? http://answall.com/questions/132100/problemas-com-utf-8-projecto-php .

2

If you are connecting to Mysql via terminal (With the famous mysql -u command -p), make sure that this connection is also with the correct Character-set.

It happens that many times (this happened to me) your PHP connection with Mysql can be perfect, all with the same encoding, Character set and collation, all perfect. But when you check through the terminal you see the broken characters.

Yes, it gives the impression that PHP and Mysql are wrong and the terminal is right, but not necessarily.

To do the test, connect to Mysql by terminal with the seginte command: mysql -u user name -p --default-Character-set=charset

Where: username is your username and charset is the charset you are wanting to configure the server.

Let’s assume that your user is root you left PHP, HTML and MYSQL configured to run in UTF-8. Your connection should look something like this:

mysql -u root -p --default-character-set=utf8
Ou então para o famoso: ISO-8859-1

mysql -u root -p --default-Character-set=latin1 If your connection occurs with your desired charset and the data is broken, then it means that there they were inserted by another charset. Ahá! We caught the mistake!

So if you change in the nail (via update) the data (Now your coenxão is in the right charset) will be correct in the terminal. If everything went right when updating your PHP page you will notice that the characters are also right there.

To set the default-Character-set in MYSQL so you don’t have to force it via terminal just specify it in your Mysql configuration file (my.cnf or my.ini).

 [mysql]
  default-character-set=seucharset
  • I changed the charset to utf-8 but still can’t properly display the Ç

  • It’s really syrup, so relax. see this link http://forum.imasters.com.br/topic/443220-resolvidoproblemas-de-acentuaca-php-mysql/

Browser other questions tagged

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