<?php
ini_set('max_execution_time', 600);
error_reporting(E_ALL);
set_time_limit(600);
$host = 'localhost';
$user =
$pass =
$db =
set_time_limit(99999);
$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Connected successfully";
}
$conn->query("SET NAMES utf8");
$date = date("m-d-y");
//$brd_query = "SELECT DISTINCT category_id,name FROM oc_category_description";
$brd_query = ("SELECT DISTINCT d.category_id,d.name FROM oc_category_description d join oc_category c on c.category_id = d.category_id where c.top=0");
$res_prd = $conn->query($brd_query);
/*foreach ($res_prd as $result) {
$result['categories'][] = array(
'category_id' => $result['category_id'],
'name' => $result['name']);
echo '<pre>';
print_r($result['categories']);
echo '</pre>';
} */
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$file = fopen("php://output", "w");
//UTF-8 encoding
fprintf($file, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($res_prd as $row) {
fputcsv($file,$row);
fclose();
}