Export Mysql database to csv file
$connect = mysqli_connect("localhost", "root", "", "test");
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen("php://output", "w");
fputcsv($output, array('ID', 'Page Title', 'Page Url'));
$query = "SELECT * FROM `page`";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_assoc($result))
{
fputcsv($output, $row);
}
fclose($output);
Comments
Post a Comment