How to save the symbol "€" in MySQL using PHP?

I installed the PHP character set in utf-8 :

 header('Content-Type: text/html; charset=utf-8'); 

I set the currency column in MySQL to varchar(1) using sorting utf8_unicode_ci .

However, the following code in PHP:

 $currency = '€'; $sql = "UPDATE myTable SET currency = '$currency' WHERE user = '$user'"; mysql_query($sql); 

Produces the following character in MySQL:

 Γ’ 

How can I get the € symbol for proper storage in MySQL?

+7
source share
3 answers

Make sure your script file is a file containing a line

 $currency = '€'; 

encoded by UTF-8. You should have this option in the editor or in the Save As dialog box.

Then make sure your connection is also encoded in UTF-8 encoding - the default is ISO-8859-1.

After connecting to the database for mySQL up to 5.0.7:

 mysql_query("SET NAMES utf8"); 

For mySQL 5.0.7 and later:

 mysql_set_charset("utf8"); 
+12
source

β€œUsing UTF-8 on the Internet” on this page gives a good description: http://dev.mysql.com/tech-resources/articles/4.1/unicode.html

+1
source

You can convert it to HTML code & euro;

-3
source

All Articles