Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Export Data From Database to CSV File

SET @TS = DATE_FORMAT(NOW(),'_%Y_%m_%d_%H_%i_%s');
SET @FOLDER = '/var/lib/sql-files/';
SET @PREFIX = 'employees';
SET @EXT    = '.csv';
SET @CMD = CONCAT("SELECT * FROM tableName INTO OUTFILE '",@FOLDER,@PREFIX,@TS,@EXT,
"' FIELDS ENCLOSED BY '"
' TERMINATED BY ',' 
ESCAPED BY '"'",
"LINES TERMINATED BY 'n';");
PREPARE statement FROM @CMD;
EXECUTE statement;
Source by hevodata.com #
 
PREVIOUS NEXT
Tagged: #Export #Data #From #Database #CSV #File
ADD COMMENT
Topic
Name
9+1 =