Is it possible to generate a CSV protegido por Senha
file from a banco MySql
using PHP
? the password is to open the file on the client.
I use this PHP script to generate the CSV file:
<?php
//export.php
if(isset($_POST["export"]))
{
$connect = mysqli_connect("localhost", "root", "", "simrede");
if (mysqli_connect_errno())
{
echo "Falha ao fazer conexão: " . mysqli_connect_error();
}
// Set utf8
mysqli_set_charset($connect,"utf8");
$connect->set_charset('utf8');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=Cadastro_Alunos-Simrede.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('lastname', 'firstname', 'department', 'institution', 'username', 'email', 'city', 'course1', 'password'),';');
$query = "SELECT * from cs_alunos ORDER BY institution";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result))
{
fputcsv($output, $row,";");
}
fclose($output);
}
?>