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 !

2 Answers 2

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 ','
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.