Home » Php » Cannot create CSV file from MySQL table

Cannot create CSV file from MySQL table

Posted by: admin October 26, 2017 Leave a comment

Questions:

The result will fail. I cannot import a CSV file. What is the problem in the query?

<?php
$conn = mysqli_connect("localhost","root","","excelupload");
$enclose = '"';
$slash = '\n';
$select = "SELECT *
FROM diamond_data
INTO OUTFILE 'excelupload/table.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '".$enclose."'
LINES TERMINATED BY '".$slash."'";

$result = mysqli_query($conn,$select);
if($result){
    echo "success";
}
else{
    echo "fail";    
}
?>
Answers: