Importing a database of products from a CSV file

6 posts by 3 authors in: Forums > CMS Builder
Last Post: August 31, 2010   (RSS)

By fsardoni - August 26, 2010

Hi is there a known issue importing a database (products) via phpmyadmin with a .CSV file? Or better yet, is there a particular way that the .CSV file needs to be formatted?
I exported what CMS Builder creates as .CSV and then use that to copy and paste all the rows of my products. Saved it and then re-upload the file to the MySQL db. However I get an error:

Invalid field count in CSV input on line 2.

what's that all about? Any helps as always, is GREATLY Appreciated.

Re: [fsardoni] Importing a database of products from a CSV file

By Chris - August 26, 2010 - edited: August 26, 2010

Hi fsardoni,

The CSV Export plugin wasn't really designed to be used this way. The plugin adds extra psuedo-fields for readability (e.g. ":label" for list fields). By default, CSV Export also removes the "dragsortorder" field from its output which isn't very human-readable.

It is possible to manually massage a CSV file into the format that phpmyadmin expects, but this can be very tricky.

Firstly, you can disable the skipping of fields by changing this line in the csvExport.php file:

$GLOBALS['CSVEXPORT_SKIP_FIELDS'] = array('dragSortOrder','createdBy._link','_filename','_link'); // These fields won't be exported from any table. Example: ('_filename','_link','lastUpdated','etc')

...to this:

$GLOBALS['CSVEXPORT_SKIP_FIELDS'] = array('createdBy._link','_filename','_link'); // These fields won't be exported from any table. Example: ('_filename','_link','lastUpdated','etc')

Next, you can manually strip out the extra fields that phpmyadmin isn't expecting. To see which fields it's expecting, do a CSV export from phpmyadmin.

Finally, when uploading your CSV file to phpmyadmin, you'll need to tell it to use commas (,) instead of semi-colons (;) for "Fields terminated by". You'd think that commas would be the default for CSV files. Go figure.

---

Alternately, CMS Builder also has a backup feature available under Admin > General Settings > Database Settings; however, it backs up and restores all the tables in its database. What exactly is your workflow here? I might be able to suggest an alternate approach that could be simpler for you if I knew what it was that you were trying to accomplish.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Importing a database of products from a CSV file

By fsardoni - August 26, 2010

Hi Chris, thanks again for your help.
What I am trying to achieve here is an import of all my products from an existing CSV.

Step 1: From PHPmyAdmin I exported the cms_products table (as a CSV file) to see what columns CMS Builder creates when I created my first product manually.

Step 2: I copied the content from my original "products" CSV into the export CSV file from CMS Builder and then tried to upload it to CMS builder DB.

In short I want to do a quick upload of all my products instead of creating each record (for my products) manually.

Re: [fsardoni] Importing a database of products from a CSV file

By fsardoni - August 26, 2010 - edited: August 26, 2010

OK. It works with your suggestion of changing the default ";" to ","...

As a note for others, it only works when changing the import from
"CSV" to "CSV using LOAD DATA" and the default "Fields Terminated By" = ";" to =","

Thank you again Chris.

Re: [fsardoni] Importing a database of products from a CSV file

Hi Fsardoni,

If you do a lot of database massaging, you might want to give Navicat for MySQL a look.

http://navicat.com/en/products/navicat_mysql/mysql_overview.html

They offer a free 30 day full version trial and also a free "lite" version of the program.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php