By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,662 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

parse CSV data sets for export to mysql with php

P: 2
Im running PHP MySQL (zen-cart) Im looking for info on CSV files with data sets and how I can import these into MySQL. I found a number of topics involving simple CSV files and I tried a number of programs designed to do this but none addressing data sets and export to multiple tables (three in my case) within a MySQL database. My CSV input text file (see example below) is comprised of lines related to one-another according to their line positions. Records are separated by empty lines. I understand there is a function in PHP called fgetcsv and I wonder how this could be used to import this format data into MySQL.

1141,DATE,"2/10/2007, 7:44 PM"
1141,CUSTOMER," Smith, Joe","Smith Nursery",""
1141,ITEM,1,1,36.00,"Actinidia Hardy Kiwi Female",7


The data is from a Palm handheld and Id like to get the orders into the zen-cart database. I must admit that it seems Im way over my head here at least maybe someone could tell me if this is even possible. Thanks.
Feb 15 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 3,235
$handle = fopen($fileName, "r");
$lines = array();
for($i = 0; ($i < $num) && (!feof($handle)); $i++) array_push($lines, fgetcsv($handle,65535));

Those three lines should leave you with a 2 dimensional array with your entire CSV's content in it.
Feb 15 '07 #2

P: 2
Thanks for the reply! I'll need to learn some basic PHP and try to fill in the rest of the script and I'll be back to report how it went. Those lines look promising.
Feb 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.