0

I have fetched a csv report which I now have in an string.

eg ->
$report="date,pageview,clicks
2012-07-01,229316,16739
2012-07-02,295238,19582
2012-07-03,278505,17805
2012-07-04,209455,15146
2012-07-05,250756,17206";

Now I want to save this data in mysql database, but not getting any optimized solution because my real $report is very large in size.

1
  • 3
    How did you fetch the string? What you should ideally do is convert it to an array as you load it with fgetcsv() Commented Jul 9, 2012 at 8:50

2 Answers 2

6

Forget using PHP to import CSV file then sending the data to MySQL- for an optimised solution use LOAD DATA INFILE and load the data straight in, you could use a temporary table if the data isn't exactly what you need

Example :

LOAD DATA INFILE '<yourcsv>' INTO TABLE <yourtable>
FIELDS TERMINATED BY ','
IGNORE 1 LINES;

Caveat - the input file needs to be locally available on the MySQL server

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

1 Comment

...assuming that you have access to the local file system of the MySQL server, which is not always the case.
0

Use fgetcsv which read records one by one in an array format. http://php.net/manual/en/function.fgetcsv.php

Comments

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.