4

How do I make special characters appear in my PHP page, knowing that I call the content using an SQL query. For example é appears as � and so on for all other special characters.

I'm using a MySQL server. The db collation was set to utf8_unicode_ci, however some attributs of the tables were set to latin1_swedish_ci

Amine
  • 1,396
  • 4
  • 15
  • 32
  • 1
    Please tell us *which* database system you're using. Different products (e.g. [tag:sql-server] or [tag:oracle]) have *different* support for various character sets. Please [edit] your question and add an appropriate tag – Damien_The_Unbeliever Oct 02 '16 at 15:48
  • Read about [_Black Diamonds_](http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored). – Rick James Oct 02 '16 at 21:12

2 Answers2

4
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;

This should work for entire DB. Source

Community
  • 1
  • 1
Penguin74
  • 480
  • 6
  • 19
  • He was happy with the answer, which was given before mine, and he asked for entire database in the comments of this another answer. My reputation was to low to answer under comments. – Penguin74 Oct 02 '16 at 18:08
1

Use the UTF-8 character set when you create a database or table:

CREATE DATABASE Soccer CHARACTER SET utf8 COLLATE utf8_general_ci;

You can find further information here.

imant
  • 597
  • 5
  • 15
  • Is there a way to change the character set for the entire DB as it is already created and contains data? – Amine Oct 02 '16 at 15:46
  • take a look at this http://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8 – imant Oct 02 '16 at 15:50
  • Thanks, I changed the collation. Yet, the characters still appear as �. – Amine Oct 02 '16 at 18:13