format('Y-m-d').'.csv', 'w'); $batch = 50; $i = 0; $data = ''; foreach ( Db::getInstance()->executeS(' SELECT CONCAT(c.lastname," ", c.firstname) as name, ca.name carrier, a.id_cart, a.id_customer, a.id_currency, a.date_add FROM ps_cart a LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`) LEFT JOIN `ps_carrier` ca ON (ca.`id_carrier` = a.`id_carrier`) WHERE a.date_add >= "'.$date_current->format('Y-m-d').' 00:00:00" AND a.date_add <= "'.$date_current->format('Y-m-d').' 23:59:59" ') as $key => $cart) { $cartObj = new Cart($cart['id_cart']); $data.= $cart['id_cart'].';'.$cart['name'].';'.$cartObj->getOrderTotal().';'.$cart['carrier'].';'.$cart['date_add']."\n"; $i++; if($i % $batch == 0) { writeFile($file, $data); $data = ''; $i = 0; } } writeFile($file, $data); fwrite($export_total, file_get_contents('tmp/export-'.$date_current->format('Y-m-d').'.csv') ); fclose($file); unlink('tmp/export-'.$date_current->format('Y-m-d').'.csv'); $date_current->add(new DateInterval('P1D')); } fclose($export_total); function writeFile($file, $data) { fwrite($file, $data); }