VeeBee
VeeBee

Reputation: 847

MySQL collation and PHP charset conflict

I have a bunch of Danish text taken from a latin-1 MySQL database and it displays correctly when echoed in PHP. The problem starts when I need to echo some other Danish characters, which are not taken from the database.

What I do is actually output the header

Content-Type: text/html; charset=iso-8859-1

to also let the non-queried characters to display correctly as well.

Problems is, when I do that the queried characters display incorrectly.

Upvotes: 0

Views: 746

Answers (2)

James C
James C

Reputation: 14149

Just because the data is stored in a latin-1 collated table doesn't mean that it's latin-1 encoded. This is due to MySQL not doing any character translation when the connection SET NAMES setting is the same as the collation.

I suspect that you have some UTF8 characters stored in a latin1 database which is confusing the issue.

For more help please can you add details of the:

  • MySQL connection encoding that you have set
  • Details of where the "non-queried" characters are coming from

Upvotes: 3

user744116
user744116

Reputation:

Use unicode. UTF-8 => the right way.

So, set utf8_unicode_ci in database, UTF-8 as page charset and before your query set mysql_query("SET NAMES UTF8");

Upvotes: 0

Related Questions