0

this is my local scenario:

I have an application which reads some CSV files and writers the content to my local MYSQL database. The content contains umlauts, such as "ß" or "Ä". Locally everything works fine, the umlauts are written to the db and also displayed correclty inside the app which reads the db.

Now I moved this scenario to the amazon cloud and suddenly "ß" becomes "?" in the db. I checked what the program reads from the CSV files and there it is still a "ß". So it must be the writing to the database I guess, question is, why was this working locally but not on my cloud server? Is this a db problem, or a PHP problem?

Thanks! :)

EOB
  • 2,975
  • 17
  • 43
  • 70
  • 2
    possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – mercator Jul 03 '12 at 08:37
  • Hard to say without any details, try [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/). – deceze Jul 03 '12 at 08:37
  • Posting duplicates is highly discouraged. You did at least re-posted here: http://stackoverflow.com/questions/11308238/inserting-umlauts-into-a-mysql-database-using-php – hakre Jul 03 '12 at 16:58

4 Answers4

2

Did you check the encoding on both databases? Most likely there might be the problem.

Peon
  • 7,902
  • 7
  • 59
  • 100
  • If it is any help, for encoding I use "utf8" and for collation I use "utf8_general_ci" and between these I have avoided the majority of character issues. – GhostInTheSecureShell Jul 03 '12 at 08:55
  • I ran this query: `SHOW CREATE DATABASE table_in_question` and for the one where it works it gave me CREATE DATABASE `table` /*!40100 DEFAULT CHARACTER SET latin1 */. Where it does not work it says utf8 instead of latin1. Does that make sense? – EOB Jul 03 '12 at 08:57
  • There you go. You have two options to solve this: 1. You change the encoding to latin1 of the other db 2. You change the db encoding on your localhost to utf8 and convert the php code to utf8. – Peon Jul 03 '12 at 09:27
1

You need to have your database UTF-8 encoded.

Here is an excellent overview article that explains how encoding works in MySQL, and multiple ways to fix it:

http://www.bluebox.net/news/2009/07/mysql_encoding/

Doa
  • 1,965
  • 4
  • 19
  • 35
0

you can use:

iconv("UTF-8", "ISO-8859-1", $stringhere);

this will convert the string for you

danyo
  • 5,686
  • 20
  • 59
  • 119
0

it all depends on how you upload the CSV file.
Before writing the data to the MySQL server, this code might help:

$Notes = $_POST['Notes']; // or contents of the CSV file- but split the data first according to newline etc.  

$charset = mysqli_character_set_name($DBConnect);  
printf ("To check your character set but not necessary %s\n",$charset);  

$Notes = str_replace('"', '"', $Notes);  //double quotes for mailto: emails.  
$von = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é");  //to correct double whitepaces as well
$zu  = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é");  
$Notes = str_replace($von, $zu, $Notes);  
echo " Notes:".$Notes."<br>" ;  
$Notes = mysqli_real_escape_string($link, $Notes); //for mysqli DB connection.

echo " Notes:".$Notes ;  
KarlosFontana
  • 188
  • 2
  • 7