accents between php and mysql how to use?

Asked

Viewed 52 times

0

what is the correct way to create the database and tables in mysql 5.6 to meet Brazilian standards of characters?

my php version is 5.6 and I use the following information in the php file header

header('Content-Type: text/html; charset=utf-8');

and in html is like this

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

but every time I search for data in the database I need to use the functions

utf8_decode();
utf8_encode();

the database was created as follows Type:Innodb, Collation: utf8_general_ci, the way it was created is correct? or it is correct to use php’s utf8 functions to fix the accent problem?

  • It can be the encoding of your file, open it with Notepad++ to check if it is as utf-8 (no good).

  • yes I am using the gift-free Notepad++ and utf-8

  • 1

    Try setting the charset on the connection as well. Here are some tips too, http://rmonte.com/acentuaca-no-php-e-mysql-com-utf-8/

  • @Augusto thanks for the tip did not know that I could set the charset by the connection, I will do the tests.

  • 4

    Blz, here also a detailed explanation http://answall.com/questions/43193/d%C3%bavida-com-charset-iso-8859-1-e-utf8? noredirect=1&lq=1

1 answer

0


Boy, I also used everything as utf-8 and still had problems with accentuation. The way I found to handle this is to run a query SET NAMES 'utf8' soon after connecting to the bank. I leave it directly in the connection file. It follows below:

//MySQLi DESENVOLVIMENTO
$db_host="localhost";
$db_port="5432";
$db_name="testedb";
$db_user="root";
$db_password="";

$dbcon = mysqli_connect( $db_host, $db_user, $db_password );
mysqli_select_db($dbcon,$db_name);
mysqli_query($dbcon,"SET NAMES 'utf8'");
  • 1

    Before answering search if there is no question and/or answer that solves the problem and then find yourself prefer to mark as duplicate instead of answer http://answall.com/search?tab=votes&q=php%20mysql%20accent

  • Okay. I’ll do it.

  • 1

    I saw several comments to create the database, and which is the best? utf8mb4? utf8_unicode_ci? or utf8_general_ci? I will use accent characters from the en-BT dictionary

  • 2

    @Wagnerfernandomomesso view Gmsantos' reply http://answall.com/a/43285/3635

  • 1

    @Wagnerfernandomomesso I usually use the utf8_general_ci for everything and never have problems.

  • @Antonioalexandrealonsodesi I also use utf8_general_ci, because I hardly make "complex" comparisons, but if you need things that have to do with sound it may be better to check the needs first, after all there are good motivations for each of these. In general for simple pages meets well, in cases of needing emojis may be necessary the aforementioned utf8mb4. Only see case by case requirements. See more staff

  • Uhum. I agree Guilherme. I like the link q vc passed.

Show 2 more comments

Browser other questions tagged

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