UTF8 only works on mysql only or on page [duplicate]

0

In coon.php that serves as a connection to my database, if I add this code:

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');

The name is as in the image below:

IfItakeitgetslikethisimage..Usingthisinthedatabaseis"Braganção" instead of "Braganção" and the problem is, when I'm going to load more stuff via json / ajax etc ... he will get "Braganção" and not "braganção"

goal: make the name stay utf8 both on the page both in the database to always pull the correct name

    
asked by anonymous 18.03.2016 / 21:09

1 answer

1

You can specify the encoding of the document shortly after starting the tag

 <?php
    header("Content-Type: text/html charset='utf-8'");
 ?>

And right after just including the structure you were already using

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');
    
18.03.2016 / 23:39