Very confused about charsets.
I've a script to download a .sql file that contains Sql tables. I use MySql. My tables are like this:
CREATE TABLE `xxx` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`notes` mediumtext NOT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I export those tables with php using this code
$mysqli = new mysqli('localhost', $user, $pass, $name);
$mysqli->select_db($name);
$mysqli->query("SET NAMES 'utf8'");
$content = "";
$queryTables = $mysqli->query('SHOW TABLES');
//the script go on creating $content
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-disposition: attachment; filename="' . $filename . '"');
echo utf8_decode($content);
exit();
When I open my sql file I found "?????" instead of "èéèàì"
Uploading the file into Plesk cause data error.
If I change
$mysqli->query("SET NAMES 'utf8'");
into
$mysqli->query("SET NAMES 'utf8mb4'");
the file is correct, but Plesk still cause data error.
N.B. Using Notepad++ I can see that, even though the file should be all in utf8, the encoding is ANSI
Which is the correct way to do this?