accents between php and mysql how to use? [duplicate]

0

What is the correct way to create the database and tables in mysql 5.6 to meet Brazilian character standards?

The version of my php is 5.6 and I use the following information in the header of the php files

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

and html is like this

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

But every time I look for data in the bank I need to use the functions

utf8_decode();
utf8_encode();

The database was created as follows: InnoDB, Collation: utf8_general_ci, how was it created correctly? or is it correct to use the php utf8 functions to correct the accent problem?

    
asked by anonymous 08.12.2016 / 19:07

1 answer

0

Boy, he also used everything as utf-8 and still had issues with accentuation. The way I found it to handle this is to run a query SET NAMES 'utf8' shortly after connecting to the database. I leave it right in the connection file. Follow 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'");
    
08.12.2016 / 19:25