473,386 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

parse CSV data sets for export to mysql with php

I’m running PHP MySQL (zen-cart) I’m 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,ORDER
1141,DATE,"2/10/2007, 7:44 PM"
1141,AMOUNT,36.00,0.00,0.00,0.00,36.00
1141,PAYMENT,Invoice
1141,CUSTOMER," Smith, Joe","Smith Nursery",""
1141,ITEM,1,1,36.00,"Actinidia Hardy Kiwi Female",7

1142,ORDER
1142,DATE,"2/13…

The data is from a Palm handheld and I’d like to get the orders into the zen-cart database. I must admit that it seems I’m way over my head here… at least maybe someone could tell me if this is even possible. Thanks.
Feb 15 '07 #1
2 3067
Motoma
3,237 Expert 2GB
[php]
$handle = fopen($fileName, "r");
$lines = array();
for($i = 0; ($i < $num) && (!feof($handle)); $i++) array_push($lines, fgetcsv($handle,65535));
[/php]

Those three lines should leave you with a 2 dimensional array with your entire CSV's content in it.
Feb 15 '07 #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

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

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
1
by: Andy | last post by:
I have a mysql db and running on RH linux , how can I export the data from the mysql db on the shell ? thx.
5
by: Kajol | last post by:
Hi All, can u plz tell me how to import data from mysql to another database. & how to export data from anotherdata base to mysql Thanx for ur Advice Regards Kajol
22
by: Illya Havsiyevych | last post by:
Hello How easily parse VB/VBA code by VB/VBA code ? Is any ready solutions ? Thank's, illya
7
by: phillip.s.powell | last post by:
We're looking at a GUI interface for our MySQL DB and I am interested in MySQL Administrator, however, one of our requirements is to be able to import/export databases. Is this possible or do I...
5
by: seddy | last post by:
Hello ! I`m kinda new to it so I found this `job` very hard therefor I ask for Your help. So, the thing is... I have this XML file ( http://www.izishop.net/export.php ) which I need to open...
0
by: lanesbalik | last post by:
hi all, right now i'm trying to migrate from db2 running under linux to mysql v5.1. i manage to export out the db2 structure & data into a del (ascii) file. but when i try to load the data...
3
by: zhif | last post by:
Hello everybody, I am trying to export the data from DB2 database to MySQL. The command I used is db2 "export to sys_state.del of del modified coldel; select * from sys_state" But, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.