I am having an issue where I send some text from a java program to a PHP page, which uploads the text to a MySQL database, and I later retrieve the text in the java program from the MySQL database (through another PHP page). The issue is that I think the MySQL database isn't using the same charset (utf-8) as the java program and the PHP page.
When I send the string "This is a super—long dash" to the PHP page, it returns from the MySQL database as "This is a super—long dash".
I know the first PHP page is receiving the correct string, because I use "echo $_POST[xxx];" to make sure.
I also use the line:
"mysql:host=$servername;dbname=$dbname;charset=utf8"
When creating the PDO to connect to the MySQL database.
I have checked the MySQL database and the string there is "This is a superùlong dash" which leads me to believe it must be some problem with the MySQL, not the PHP or Java.
I tried to correct this by using the fixUTF8 function in the solution here: Detect encoding and make everything UTF-8 by Sebastián Grignoli. However, as a result I get "This is a super?long dash".
EDIT:
Here is my PHP code for uploading to MySQL:
<?php
$servername = "**********";
$username = "**********";
$password = "**********";
$dbname = "**********";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("INSERT INTO authors (first_name, middle_name, last_name, blurb)
VALUES (?, ?, ?, ?)");
$stmt->execute(array("$_POST[firstName]", "$_POST[middleName]", "$_POST[lastName]", "$_POST[blurb]"));
echo "New author created successfully";
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
EDIT2:
Here is what SHOW CREATE TABLE authors
provides: