I am using Wamp server 2.1 on windows 7 with PHP 5.3.4, Apache 2.2.17, MySql 5.1.53.
httpd.conf: AddDefaultCharset "iso-8859-1"
php.ini: default_charset = "iso-8859-1"
I am using php mysqli class to insert data in a table with latin1 encoding, and column with latin1 encoding, latin1_swedish_ci collation. In the php file, I set charset as ISO-8859-1 via meta tag, I render a form with accept-charset="ISO-8859-1" attribute. I use mysqli::set_charset to set charset of the database connection to latin1, but still the data being entered is corrupted. As per my understanding, the data is valid latin1 characters.
The code:
$dbMain->set_charset('latin1');
$query = "INSERT INTO `table` (" . implode(',', array_keys($data)) . ") VALUES ('" . implode("','", array_values($data)) . "')";
$dbMain->query($query);
The data being corrupted: "the characters Ä, Ö, Ü, ä, ö, ü, and ß. Shop-Produkte für die Elektronik"
When I read the data through latin1 connection, it gives me garbage (black diamonds with question marks) instead of the data I inserted. When I read the data through utf8 connection, it shows me proper characters. Same in SqlYog (MySql client).. If I run "SET NAMES latin1" and browse the table, I see barbage characters. If I run "SET NAMES utf8" and browse the table, I see proper text. What's wrong here?
Update:
I ran the following queries in MySql client:
SET NAMES latin1;
SELECT my_column,HEX(my_column) FROM my_table;
and got this result
|my_column|HEX(my_column)|
--------------------------
| ß | C39F | (entered manually from MySql client)
| � | DF | (entered from php via latin1 connection)
Has my database gone cucu?
$data
come from? – Esailija