- This topic has 12 replies, 1 voice, and was last updated 2 months, 1 week ago by 32gbsd.
- November 7, 2020 at 6:44 pm #1762Luzaan23RocksParticipant
I am looking for a good importing library that will assist in validating the csv data against a database table, manage duplicate entries etc.
Can anyone suggest a good library?
Thank you in advance!November 7, 2020 at 6:44 pm #1763alexanderpasGuest
league/csv found at https://csv.thephpleague.com/
Alternatively, parsecsv/php-parsecsvNovember 7, 2020 at 6:44 pm #1764Annh1234Guest
LOAD DATA INFILE … INTO TABLE … FIELDS TERMINATED BY . ENCLOSED BY . LINES TERMINATED BY . ;
then to ignore duplicates, create your table with the unique key, and INSERT IGNORE .. SELECT…
No need for a library for this… Not unless your text is not really CSV, and it’s corrupt…November 7, 2020 at 6:44 pm #1765pragmageekGuest
i found [https://github.com/box/spout](https://github.com/box/spout) to be hugely performant.November 7, 2020 at 6:44 pm #1766blacm00nGuest
I would suggest league php.
https://csv.thephpleague.comNovember 7, 2020 at 6:44 pm #1768psysunGuest
Question because I’ve never heard of a library doing such a thing…
Is there built in functions or what have you to actually compare a csv file to a database, managing duplicate entries?
I’ve more or less done the csv parsing and then painstakingly had to do some array comparisons or whatever to compare and find duplicates and the like.November 7, 2020 at 6:44 pm #1769nunchaqGuest
I did wrote one myself. I could find anything that had all things I needed (Column mapping, dates to object etc). It’s honestly simple to write unless you need this ASAP than I would suggest write it yourself.
Edit – grammarNovember 7, 2020 at 6:44 pm #1770badasimoGuest
I’m really happy to see all the options that other people are posting, hopefully this is a high google result in the future for people looking to solve this problem. In the past I have used things like phpmyadmin, or written my own. There are some frameworks/software that eat CSVs kind of nice– you can use Drupal migrations to import CSV in a very advanced way, also a software called Quick Base has a pretty decent CSV importer.November 7, 2020 at 6:44 pm #1771[deleted]Guest
The most popular library would be the csv package by league as already mentioned a few times in this thread. That being said it’s easy to build your own using the built-in fopen and fgetcsv functions. I built one that I’ve used on multiple projects that only has 3 methods.November 7, 2020 at 6:44 pm #1772Jascar_DestinGuest
I would suggest SpoutNovember 7, 2020 at 6:44 pm #1773whatshisnutsGuest
I have been using -[https://phpspreadsheet.readthedocs.io/en/latest/](https://phpspreadsheet.readthedocs.io/en/latest/) / [https://github.com/PHPOffice/PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet)- which is definitely a very large hammer for this use case. But I’ve built some intricate excel reporting files with it and it’s been efficient and very easy to work with.November 7, 2020 at 6:44 pm #1774rias500Guest
https://github.com/spatie/simple-excel is a nice abstraction over box/spoutNovember 7, 2020 at 6:44 pm #177532gbsdGuest
Its better to code it yourself using raw php. You will end up with a tonne of edge cases that libraries will not support. There was this one instance where I had to switch out the separation car…wait this is not a help forum!
- You must be logged in to reply to this topic.