1

First I did this simple query from MySQL workbench :

UPDATE PRODUIT
SET statut = "Expedié"
WHERE num_ref like "14T500924001"

And it save exactly the same value for statut field. Then I put this query in my php file like this :

$bdd->query('UPDATE PRODUIT SET statut = "Expedié" WHERE num_ref like "14T500924001"'); 

The difference its for the field statut it doesn't take the "é" from "Expedié" ... how can I fix this ? It shows me this : "Expedié"

In my html->head, I put this : <meta charset="utf-8"> but didn't change a lot.

UPDATE1

How I get $bdd :

function ConnexionBDD(){
try{
    $bdd = new PDO('mysql:host=127.0.0.1:3306;dbname=NumeroSerie', 'root');
     $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $e){
    die('Erreur : '.$e->getMessage());
}
catch   (PDOException $pe)
{
die ("I cannot connect to the database." . $pe->getMessage());
}
return $bdd;    
};
Booba__2012
  • 143
  • 1
  • 3
  • 14
  • How do you get `$bdd`? The problem seems to lie in the wrong encoding set in the database connection. – andy Sep 24 '14 at 10:33
  • Have you tried to use a html special character like this: `é` from: http://www.utexas.edu/learn/html/spchar.html – SuperDJ Sep 24 '14 at 10:41
  • please update your database collection "utf8_bin" and try again. it will allow you to store such characters. see http://stackoverflow.com/questions/13004892/how-to-convert-%C3%83%C2%A9-%C3%83%C2%AA-in-database-mysql-to-the-normal-string-%C3%A9-%C3%A2-using-ph#answer-13004917 for more. – arpit desai Sep 24 '14 at 10:44
  • @SuperDJ : You mean in my query of php, when i do the SET i put instead of "Expedié" -> "Expedi&eacute" ? – Booba__2012 Sep 24 '14 at 10:46
  • @Booba__2012 yes someting like that. If you store it like that in a database it should return as Expedié when you retrieve the data – SuperDJ Sep 24 '14 at 10:48
  • I tried but it saved me the value "Expedi&eacute" but its fine i get my answer. – Booba__2012 Sep 24 '14 at 10:53

2 Answers2

2

To set your database connection to use utf8 encoding, use

$bdd = new PDO('mysql:host=127.0.0.1:3306;dbname=NumeroSerie;charset=utf8', 'root');

In addition, you need to make sure that your php source file is also encoded in utf8.

Specifying the character encoding in your html with <meta charset="utf-8"> does not change the encoding of your database connection. The alternative to the solution above would be to tell the browser you are sending iso-8859-1 encoding with <meta charset="iso-8859-1">.

andy
  • 2,002
  • 1
  • 12
  • 21
0

Try this:

$bdd = new PDO('mysql:host=127.0.0.1:3306;dbname=NumeroSerie;charset=utf8', 'root');
Gervs
  • 1,397
  • 9
  • 8