2

We have split up a CSV file into individual lines and those lines have been stored into a database. Normally I would use fgetcsv to import each line of a file into an array when it is imported. However, since the CSV data is now stored in the database, I cannot use that function anymore. Is there an equivalent function that would import a single csv line as a string and then break it into and array?

I realize I could just explode based on "," but there are some other issues with doing that like the way Excel uses quotations around some fields, etc.

3
  • 2
    "We have split up a CSV file into individual lines and those lines have been stored into a database." YOU'RE DOING IT WRONG. Databases are for storing structured data; you should split it up (and normalize it) before storing in the database. Commented Nov 10, 2010 at 19:19
  • We're using the database as a queue for later processing. It is really just temporary storage, not long term usage. Commented Nov 10, 2010 at 19:25
  • It's getting pretty old having people always comment that a denormalized database is inherently wrong. Yes, you should normalize for most standard applications, but it's simply not always the case; knee-jerk reactions are not the solution, critical thought is. Commented Nov 10, 2010 at 19:46

1 Answer 1

3

https://www.php.net/manual/en/function.str-getcsv.php

Agree with previous comment though, you probably shouldn't be putting CSV data in your database unless there's a compelling reason to do so (and there are some).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I should have been able to find that myself. Sorry about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.