[Eug-lug] Importing a .csv file into MySql

Ron LeVine levine.ron at gmail.com
Wed Aug 22 17:02:29 PDT 2007


I am helping a friend with "OSCommerce" which is a PHP/MySQL based eCommerce
solution. She gets a .csv file from her supplier with all the products
available and rather than hand enter/modify 20,000 products, it would be
nice to just have MySQL just import them.

The file is a CSV export from Excel in the form of:


 SKU
 ITEMID
 DESCRIPTION
  VENDOR
 CAT
 PRICE
 Weight
 SIZE
 UNIT
 SUB-CATEGORY
 STATUS
  FR
 LA
 AT
 CH
 DA
 HO
 KA
 NJ
 TA
 MI
 PO
 LR

The MySQL DB record structure has some of these catagories, but not all and
has some catagories that are not listed here that are used for site
maintenance.

So, I need to parse the file for the info that is needed and stick it into
the relavant records. Doing a wholesale batch import isn't really feasable.

Thanks again,
Ron


On 8/22/07, Allen Brown <abrown at peak.org> wrote:



The answers you are getting are geared toward telling you where
> to learn how to do the job.  If you want more specific help
> you may want to be more specific with your question.  Posting
> the exact format of the data and how you want it to be
> organized under MySQL will empower folks to give you a better
> answer.
> --
> Allen Brown  abrown at peak.org  http://brown.armoredpenguin.com/~abrown/
>    Always forgive your enemies -- Nothing annoys them so much. ---Oscar
> Wilde
>
> Ron LeVine wrote:
> > Well, guys, you both are talking way over my head on this.
> >
> > Oh well.
> >
> > Thanks anyways,
> > Ron
> >
> > On 8/22/07, *larry price* < laprice at gmail.com
> > <mailto:laprice at gmail.com>> wrote:
> >
> >     On 8/22/07, Ron LeVine < levine.ron at gmail.com
> >     <mailto:levine.ron at gmail.com>> wrote:
> >      > Greetings all,
> >      >
> >      > I have a .csv file from a spreadsheet that I want to import into
> >     a MySQL db.
> >      > Unfortunately, the format of the file is not the same as the
> >     field list in
> >      > MySQL so I think I need a script to parse the file and then do
> >     the MySQL
> >      > commands to place the data where it goes.
> >      >
> >
> >     This is a very straightforward data filter script, the general
> pattern
> >     goes like this
> >
> >     using your favourite scripting language
> >
> >     read each line of the file into a hash table (dictionary)
> >
> >     write the output function that does whatever formatting,
> interpolation
> >     and calculation you need to produce the database table row you need
> >     from the hash structure you have.
> >
> >     apply the output function to each line, and either stuff the result
> >     into the database directly, or into a file for importation later.
> >
> >     (for larger data sets the copy function your DBMS has is
> significantly
> >     faster than inserting row by row)
> >
> >
> >
> >
> >
> >
> >      > I am not much of a script guy. Anyone care to assist on this???
> >      >
> >      > Thanks in advance,
> >      > Ron
> >      >
> _______________________________________________
> EUGLUG mailing list
> euglug at euglug.org
> http://www.euglug.org/mailman/listinfo/euglug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://euglug.org/pipermail/euglug/attachments/20070822/3f5e616f/attac=
hment.htm


More information about the EUGLUG mailing list