In my site when Admin is logged in I want him to be able to export a table in phpmyAdmin to a Excel sheet. I was able to do it manually by export button in phpMyAdmin but I want to be able to do this using a SQL statement. This is the first time I am trying it and after looking at exporting-table-structure-to-excel-files-with-phpmyadmin and phpmyadmin-exporting-to-csv-for-excel
I wrote the following code.
if($level==1){
echo "<br>";
$q9=" SELECT * INTO OUTFILE 'C:\xampp\htdocs\excelsheet1.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY ''
LINES TERMINATED BY '
'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE('db1') AND TABLE_NAME ='tb1'";
$s9=mysql_query($q9,$connect) or die("couldn't export values");
}
I have created a blank .csv fie in C:\xampp\htdocs
named as excelsheet1.csv
. But when I run this code it gives the error couldn't export values
and there's a blank excel sheet. In the PHP statement how can I write OPTIONALLY ENCLOSED BY '"'
inside SELECT because if I use "
inside SELECT I get a syntax error. What can I do to export values in tb1 to excelsheet1.csv