note 127666 added to function.fputcsv
| From: | polygon dot co dot in at gmail dot com | Date: | Sat, 24 Sep 2022 11:30:20 +0000 |
| Subject: | note 127666 added to function.fputcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219612@lists.php.net to get a copy of this message | ||
When it comes to download CSV for any project, we face problem of memory limit when trying to
downloads more than 30,000 records at a time.
Have tried to solve this to an extent by using mysql client via shell.
<?php
$filename = 'project_data.csv'; // replace this with your desired dynamic zip file name
//SQL for content to download
$sql = '
SELECT
column1 as COLUMN1,
column2 as COLUMN2
FROM
TABLE_NAME
WHERE
column3 = "'.addslashes($_POST['column3']).'"
';
// Shell command
$command = 'mysql \\
--host='.escapeshellarg(HOSTNAME).' \\
--user='.escapeshellarg(USERNAME).' \\
--password='.escapeshellarg(PASSWORD).' \\
--database='.escapeshellarg(DATABASE).' \\
--execute='.escapeshellarg($sql).' \\
| sed -e \'s/"/""/g ; s/\t/","/g ; s/^/"/g ;
s/$/"/g\'';
// CSV headers
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$filename}");
header("Pragma: no-cache");
header("Expires: 0");
// execute shell command
echo shell_exec($command); // execute shell command
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 103.58.154.93)
----
Manual Page -- https://php.net/manual/en/function.fputcsv.php
Edit -- https://main.php.net/note/edit/127666
Del: integrated -- https://main.php.net/note/delete/127666/integrated
Del: useless -- https://main.php.net/note/delete/127666/useless
Del: bad code -- https://main.php.net/note/delete/127666/bad+code
Del: spam -- https://main.php.net/note/delete/127666/spam
Del: non-english -- https://main.php.net/note/delete/127666/non-english
Del: in docs -- https://main.php.net/note/delete/127666/in+docs
Del: other reasons-- https://main.php.net/note/delete/127666
Reject -- https://main.php.net/note/reject/127666
Search -- https://main.php.net/manage/user-notes.php