note 127665 added to function.shell-exec
| From: | polygon dot co dot in at gmail dot com | Date: | Sat, 24 Sep 2022 07:52:04 +0000 |
| Subject: | note 127665 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219611@lists.php.net to get a copy of this message | ||
shell_exec() returns string but when this comes to multiline output it is still a multi line string.
$sql = '
SELECT
column1 as COLUMN1,
column2 as COLUMN2,
FROM
TABLE_NAME
WHERE
column3 = "'.addslashes($_POST['column3']).'"
';
$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\'';
echo shell_exec($command); // execute shell command
// Outputs data.
"COLUMN1","COLUMN2"
"data11","data12"
"data21","data22"
This can be extended for CSV download with below headers.
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$filename}");
header("Pragma: no-cache");
header("Expires: 0");
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 203.192.195.146)
----
Manual Page -- https://php.net/manual/en/function.shell-exec.php
Edit -- https://main.php.net/note/edit/127665
Del: integrated -- https://main.php.net/note/delete/127665/integrated
Del: useless -- https://main.php.net/note/delete/127665/useless
Del: bad code -- https://main.php.net/note/delete/127665/bad+code
Del: spam -- https://main.php.net/note/delete/127665/spam
Del: non-english -- https://main.php.net/note/delete/127665/non-english
Del: in docs -- https://main.php.net/note/delete/127665/in+docs
Del: other reasons-- https://main.php.net/note/delete/127665
Reject -- https://main.php.net/note/reject/127665
Search -- https://main.php.net/manage/user-notes.php