3

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 !

Anuraag Kapoor
  • 101
  • 1
  • 8

2 Answers2

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.

  1. get all the files from specific folder using scandir
  2. parse csv files using fgetcsv
  3. write database connection code and insert query to insert csv records.
  4. 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

Community
  • 1
  • 1
Jayson
  • 1,105
  • 7
  • 25