I have a html form that stores data to mysql. When special characters are used (øæå), it store the characters correcly in the database.
When i use a script to save the mysql table to an CSV file, the CSV file wont show special characters correct anymore.
Any ideas?
$conn = mysqli_connect($hostname, $user, $password, $database, $port);
if (mysqli_connect_errno()) {
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
$csv_export = '';
$query = mysqli_query($conn, "SELECT * FROM ".$db_record);
$field = mysqli_field_count($conn);
for($i = 0; $i < $field; $i++) {
$csv_export.= mysqli_fetch_field_direct($query, $i)->name.';';
}
$csv_export.= '
';
while($row = mysqli_fetch_array($query)) {
for($i = 0; $i < $field; $i++) {
$csv_export.= '"'.$row[mysqli_fetch_field_direct($query, $i)->name].'";';
}
$csv_export.= '
';
}
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=".$csv_filename."");
echo($csv_export);