Search code examples
phpxmlcsvtabular

To use CSV or XML for data imports?


I'm writing a script were I want to be able to import data into a database table. The table is either mysql, SQLite 3, or PostgreSQL. Hypothetically, it could be a lot of data (the data is products/categories/descriptions etc for e-commerce software).

What's the best (fastest and more universally used) format to hold such data in? And what is the best way to import the data?

I've done some research, but it just made the question harder imo. For example, some say that csv is better because it's smaller, some say xml is worse because there isn't one standard.. some say xml is better because the data is easier to handle.

Thoughts? I'm open to other formats as well. And the software is written in php if that makes a difference.


Solution

  • I think CSV and XML have different purposes :

    • for storing raw tables data, csv is a quite exact representation of a table (that's it : columns and rows). So it is easy to manipulate, but does not allow you to reproduce relationships, which might be a problem if data consistency is a requirement
    • for serializing entities orobjects, XML is the way to go : it offers a tree structure and is quite readable. and XML has some advantages : you can use DTDs or XSDs for validating data, it's tree structure can be used to maintain data consistency...

    Latest versions of mysql support XML importing : http://dev.mysql.com/doc/refman/5.5/en/load-xml.html