Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnicholas maddren
12,793 PointsCSV to Database?
I have a CSV file that contains vehicle specifications, this file is updated on my server daily. How would I go by making the database update with the CSV file? Thanks
1 Answer
Ryan Duchene
Courses Plus Student 46,022 PointsPHP has a few functions built into it for handling CSV:
After you get the CSV into an array, though, it's a fairly simple matter to get it into the database. Randy's course on Using PHP with MySQL covers all of that.
PHP is probably not your best bet for this, as it's mostly web-oriented. It can get the job done, but I don't think it's the best tool for the job. To be honest, you're probably better off writing a Ruby or Python script for this.
nicholas maddren
12,793 Pointsnicholas maddren
12,793 PointsThanks for the reply, so I've just had a look for a solution to importing a CSV file into a database with python and can't seem to find any results. I've searched treehouse also but I can't seem to find out how I would go by doing this. I have only ever used Python once and that was just simple changes. Any idea where I can find more about this?
Thanks
Ryan Duchene
Courses Plus Student 46,022 PointsRyan Duchene
Courses Plus Student 46,022 PointsI know that Treehouse will be releasing their first course on Python in July. (Can't wait for that!)
After some searching, I found a library for connecting Python with MySQL.
Python also has a built-in module specifically for working with CSV files; you can find the documentation for it here (version 3+).
Hope this helps!