Is it possible to upload data from CSV file to my database AUTOMATICALLY ? I am making a PHP project , in which It is needed the database to get updated from a specified path folder . Kindly help !
Asked
Active
Viewed 2,911 times
2 Answers
1
This can be archived with plain SQL on the server. Take a look at LOAD DATA INFILE Statement: https://dev.mysql.com/doc/refman/5.7/en/load-data.html
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test
FIELDS TERMINATED BY ','

PKeidel
- 2,559
- 1
- 21
- 29
0
Yes its easy to implement. you have to create one PHP
script.
- get all the files from specific folder using
scandir
- parse csv files using
fgetcsv
- write database connection code and insert query to insert csv records.
- set PHP script in Cron Scheduler which would take your CSV entries, format into INSERT SQL statements and fire the query.
Useful links: http://php.net/manual/en/function.scandir.php
How to parse a CSV file using PHP
http://coyotelab.org/php/upload-csv-and-insert-into-database-using-phpmysql.html