I'm trying to insert data in a mysql database. These data often has german umlaute in it.
I'm using this method:
function insertMenue($content, $date) {
$session = $_SESSION['aid'];
global $pdo;
$pdo->exec('SET CHARACTER SET utf8');
$params = ["menue", "<p>".changeAttr($content)."</p>", $date, $session];
// Check all your params are set...
// Although you may want to consider checking these before entering this block
print_r($params);
echo "c".changeAttr($content);
print_r("v". changeAttr($content));
$sql = "INSERT INTO menue( type
, content
, date
, creator
)
VALUES( ?
, ?
, ?
, ?
)";
try {
$sth = $pdo->prepare($sql);
$sth->execute($params);
} catch (PDOException $e) {
throw new pdoDbException($e);
}
}
As you see I'm already doing some debugging. I'm getting the data from an Excel .xls file. The print_r grants an output like this:
Salat
****
Trutenpiccata Tomatensauce
Spaghetti
Gem�sebuffet
-
****
Saisonfr�chte
When I check the mysql database everything including the � and after gets deleted. Like:
Salat
****
Trutenpiccata Tomatensauce
Spaghetti
Gem
I tried to encode the data as utf-8 from the insert method on and I set the database to utf-8 by:
ALTER DATABASE mensaapp CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE menue CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Where do I miss the point to encode the data to utf-8?