Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL and UTF-8 (SQL SCRIPT)

Tags:

sql

mysql

I want to insert special characters in a MySQL DB (5.6.17). Not with a PHP script but in full SQL.

It's work with all characters "ù « » ê –" except for "à".

I need help, Thanks :)

DB Script :

create table movie (
mov_id integer not null primary key auto_increment,
mov_name varchar(100) not null,
mov_description_short varchar(500) not null,
mov_description_long varchar(2000) not null,
mov_author varchar(150) not null,
mov_year integer not null,
mov_poster varchar(150) not null) engine=innodb character set utf8 collate utf8_unicode_ci;

My SQL script :

INSERT INTO movie (mov_name, mov_description_short, mov_description_long,mov_author,mov_year,mov_poster) 
VALUES ('Hunger Games : La Révolte, partie 2', 'Hunger Games : La Révolte, partie 2 est un film américain de science-fiction dystopique réalisé par Francis Lawrence, sorti en 2015.Il met en scène le personnage principal Katniss Everdeen interprété par Jennifer Lawrence et fait suite Ä Hunger Games (2012), L''Embrasement (2013) et Ä Hunger Games : La Révolte, partie 1 (2014).', 'Alors que Panem est ravagé par une guerre désormais totale, Katniss et le Président Snow vont s''affronter pour la dernière fois. Katniss et ses plus proches amis – Gale, Finnick, et Peeta – sont envoyés en mission pour le District 13 : ils vont risquer leur vie pour tenter d''assassiner le Président Snow, qui s''est juré de détruire Katniss. Les pièges mortels, les ennemis et les choix déchirants qui attendent Katniss seront des épreuves bien pires que tout ce qu''elle a déjà pu affronter dans l''arène...','Francis Lawrence',2015,'images/Hunger_Games_La_revolte_Partie_2.png');

The result on my PHP application : enter image description here

like image 957
YoannLth Avatar asked Dec 07 '25 05:12

YoannLth


1 Answers

Two things are required to store UTF-8 data from an SQL file :

  1. Your SQL file has to use the UTF-8 character encoding. I think you are using latin1 (ISO8859-1 or ISO8859-15) for now. Check your text editor options for that.
  2. Your connection to the DB must use the UTF-8 character encoding. For that you have to execute the following SQL query before any other query :

    SET NAMES utf8;

The actual database storage should be UTF-8, but since you are only storing french characters it could be latin1 too.

like image 101
Derek Avatar answered Dec 08 '25 18:12

Derek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!