Title: Auto Import CSV
Last modified: August 21, 2016

---

# Auto Import CSV

 *  Resolved [champeaub](https://wordpress.org/support/users/champeaub/)
 * (@champeaub)
 * [12 years ago](https://wordpress.org/support/topic/auto-import-csv/)
 * Hey xnau,
 * First off, your plugin is awesome. I am hoping your plugin is the solution to
   my problem. I am using your plugin for something a little different. I can go
   into detail about this if you like, but I don’t want it to distract from my question.
 * I am wondering if there is a way I can auto import a csv on a 15 minute interval?
 * Sincerely,
 * Ben Champeau
 * [https://wordpress.org/plugins/participants-database/](https://wordpress.org/plugins/participants-database/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923316)
 * Yes, there are several ways to do this…it’s certainly going to require advanced
   programming skills. Probably easiest to hook into the WP chron with a callback
   that grabs the CSV (from the server or from a remote address) and triggers an
   import to the database…that can be done either directly using WP $wpdb methods
   or by sending the file to the plugin to be imported by the plugin’s CSV import.
 * I can’t go into much detail, I haven’t tried anything like this, I’m not sure
   what complications you’ll run in to…in other words, you’ll be on your own. If
   you need to ask more technical questions about the plugin, use my support email.
 *  Thread Starter [champeaub](https://wordpress.org/support/users/champeaub/)
 * (@champeaub)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923400)
 * Hey xnau,
 * Thanks for the response. I was afraid this was going to be the answer, ha! I 
   started to look into the WP chron, but I thought I would ask you before I dove
   in. I will let you know how it goes!
 * Thanks again!
 *  Thread Starter [champeaub](https://wordpress.org/support/users/champeaub/)
 * (@champeaub)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923480)
 * Hey xnau,
 * I got it up and working. I decided to work directly with the mySQL database. 
   Here is a quick overview of how I got it working.
 * Using cron job on the linux server:
    1. I grab the csv from the network.
    2. Parse and format the CSV with a php script to better import into mySQL.
    3. Truncate the wp_participants_database table and import into mySQL.
 * If anyone would like more detail in how I did this, or you run into issues let
   me know. I most likely ran into a lot of the same issues.
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923481)
 * that’s great… thanks for sharing how you did it.
 *  [Brejen2014](https://wordpress.org/support/users/brejen2014/)
 * (@brejen2014)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923514)
 * Hi champeaub,
 * Could you please share how you accomplished this?! I’m very interested in learning
   it. My goal is to REPLACE ALL records in the the participants db with new records
   by importing a CSV file every X number of hours. I may only have 400+ rows every
   update.
 * Thanks,
 * Brejen
 *  [micron2](https://wordpress.org/support/users/micron2/)
 * (@micron2)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923515)
 * Hi champeaub,
    would appreciate more details oh how you did it. Better focus 
   on your points 1,2,3. Thanks. Thank you xnau for great job.
 *  Thread Starter [champeaub](https://wordpress.org/support/users/champeaub/)
 * (@champeaub)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923516)
 * Hey there,
 * Sorry I missed your message. It is a bit late for me now. I will get back to 
   you guys tomorrow morning!
 * Goodnight!
 *  [relidtm](https://wordpress.org/support/users/relidtm/)
 * (@relidtm)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923517)
 * Yes do you have this process somewhere? I am trying to do something very similar.
 *  Thread Starter [champeaub](https://wordpress.org/support/users/champeaub/)
 * (@champeaub)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923518)
 * Alright,
 * The first thing I will say the Participant Database plugin has a specific purpose,
   and is most likely not your solution. The Participant Database plugin is pretty
   awesome, but if you are looking for something that can fit a wider set of solutions
   look into PODS Framework plugin.
 * With that said here is how I setup this up.
 * I am using this plugin to simply display an employee schedule. The software that
   is used here to schedule employees is beyond limited, but we wanted a way to 
   display the schedule online. Luckily the software was capable of exporting the
   schedule to CSV every time the schedule was saved.
 * Make sure the CSV you have is setup the way you want it setup. The CSV file that
   I got from the scheduling software had a lot of extra data that was not needed.
   So, I created a PHP script that read in the CSV, stripped out the data not needed,
   and then wrote the data to a new CSV.
 * Once your CSV is set go to the “Manage Database Fields” under the Participant
   Database plugin. You need to delete whatever fields are under Participant Info
   Fields, and put in the same fields that are in your CSV.
 * The website I maintain is hosted on-site, and runs on Ubuntu 12.04. On the server
   I setup a chron job that looks like this:
 * cp -f /path/to/file /place/to/copy/to && php5 /path/to/script && mysql -uusername-
   ppassword database name < path/to/import.sql
 * The first command is copying the csv off the network onto the server.
 * The second command is running the php script I created to create the stripped
   version of the csv.
 * The third command is logging into sql and into the wordpress database and telling
   it to run the commands in the import.sql file.
 * There is probably a much more secure way to do this than putting your sql password
   in a scheduled task . . . I just haven’t taken the time to improve the process.
 * Here is a copy of my import.sql
 * truncate table wp_participants_database;
    LOAD DATA LOCAL INFILE ‘/path/to/csv’
   INTO TABLE wp_participants_database FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘ 
   LINES TERMINATED BY ‘\n’ IGNORE 1 LINES (field_1, field_2, field_3, field_4);
 * Explanation of import.sql:
 * truncate table – this deletes all data in table
 * LOAD DATA LOCAL INFILE – This tells sql to import the csv
 * INTO TABLE – this tells it what table to import the csv to
 * FIELDS TERMINATED BY ‘,’ and ENCLOSED BY ‘”‘ and LINES TERMINATED BY ‘\n’ – just
   keep these in here to be safe
 * IGNORE 1 LINES – if your csv has a header (first row is the name of your fields)
   then include this.
 * (field_1, field_2, field_3, field_4) – the name of these fields are the same 
   as the field names you listed in Manage Database Fields and your csv.
 * I don’t know if I provided enough detail. Let me know if this helps or not. If
   you have a specific question let me know.
 * Here are some of the things I read up on to help me understand what I was trying
   to do.
 * mySQL
    [mysql 5.5 LOAD DATA INFILE syntax](http://dev.mysql.com/doc/refman/5.5/en/load-data.html)
 * PHP – if you plan on making a script
    [fgetcsv](http://php.net/manual/en/function.fgetcsv.php)
   [fputcsv](http://us1.php.net/manual/en/function.fputcsv.php)
 * I can share my script if anyone is interested. It probably doesn’t follow best
   practice but it gets the job done.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Auto Import CSV’ is closed to new replies.

 * ![](https://ps.w.org/participants-database/assets/icon-256x256.jpg?rev=1389807)
 * [Participants Database](https://wordpress.org/plugins/participants-database/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/participants-database/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/participants-database/)
 * [Active Topics](https://wordpress.org/support/plugin/participants-database/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/participants-database/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/participants-database/reviews/)

 * 9 replies
 * 5 participants
 * Last reply from: [champeaub](https://wordpress.org/support/users/champeaub/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/auto-import-csv/#post-4923518)
 * Status: resolved