Problems with UTF-8 ISO-8859-1 mysql php accentuation

Asked

Viewed 3,115 times

2

I’m having stress problem using PHP/Mysql

When I use:

header("Content-Type: text/html; charset=UTF-8",true);
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

the HTML code is ok, but accentuated Mysql results gets.

I switch to:

header("Content-Type: text/html; charset=ISO-8859-1",true);
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

the problem reverses, the database results are ok and html is:

Next (e.g.: Next)

I’ve moved the database to Latin1 and back to UTF-8 and nothing. I tried utf8_encode(), htmlentities() and it’s still the same.

Any suggestions?

  • Try to user this CREATE DATABASE mydb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

  • @Andersoncarloswoss the information there did not solve

  • @Lucascarezia already tried with utf8 and latin1 .. same result

2 answers

2

On your connection, use set_charset:

$connMysql = mysql_connect('localhost', $myUser, $myPass);
mysql_select_db($database, $connMysql);
mysql_set_charset('UTF8');

2


If your database is encoded differently from your code you can use PHP example:

mysql_query("SET character_set_results = 'utf8'");

Replace the 'utf8' for your preferred encoding. But the ideal is to analyze if your code files and database are with the standard encoding so you won’t have these problems.

Browser other questions tagged

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