Recently I try to make a WebApp to make weekly report for my work. Then I found an issue about importing large file to MySQL, my data type is CSV and it has about 1 Mil record (Holy !). Then I was wondering how to import this to MySQL by PHP, it takes an age. You can try to upload it at night and it will be done in the morning. Then it’s not the answer I need for my case. After doing some research on the internet, I found this function from MySQL. Yes its LOAD DATA INFILE. It is very simple, and also its work very fast.
The command is
LOAD DATA LOCAL INFILE ‘$file’
INTO TABLE depo
FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n’
IGNORE 1 LINES
Okay lets try how to make Simple import function with PHP.
First, make table on MySQL Database with this structure
Then make connection script to your database and name it connect.php.
After that make new file and name it import.php, and then write this.
Then you can try this import function!
Walah it works! I just need 30 secs to import 550K record from 100 MB file. Hope this can help you guys and save your day!
Well if you having error about File upload is too large you can Fix it here How to Fix ERROR:File upload is too large
Here credits : Stackoferflow-PHP Import CSV File to MySQL Database