homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Import CSV zipped file date to mysql

 4:00 pm on Feb 11, 2010 (gmt 0)

How do i import a CSV file that is zipped.
CSV file = xyz.txt
Zipped file = xyz_zip.zip

I have worked on the following code to get the whole xyt.txt date into a variable ($content).

$zip = zip_open("xyz_zip.zip");

if ($zip)
while ($zip_entry = zip_read($zip))
if (zip_entry_open($zip, $zip_entry))
$contents = zip_entry_read($zip_entry,zip_entry_filesize($zip_entry));
echo "$contents<br />";

The problem is that fopen() need a CSV file but i have is a variable with the content of the CSV file.

How do i import $content data into mysql database ?

Please help.



 4:34 pm on Feb 11, 2010 (gmt 0)

I don't understand why you need to use fopen if you already have the contents in a var

why not just insert the content of that var into the db then?


 5:01 pm on Feb 11, 2010 (gmt 0)

I am quite new to php.
How do i insert the content of a variable into the db.
The contents is records like below :
I have to insert Name, Address, Age into the db from the var.


 7:19 pm on Feb 11, 2010 (gmt 0)

ah I get it now

it looks like there is a new line, you could split it on the newline character, which would return an array

you could then loop through that array and split each row on the | and then insert those pieces into the db


 4:23 pm on Feb 12, 2010 (gmt 0)

Got it to work finally.
Now i have another problem. The zip files that i have to import is large (something is GB's). This is causing the memory to get exhausted.
Is there a way of splitting these zip files in PHP ?


 6:06 pm on Feb 13, 2010 (gmt 0)

just don't read the whole thing into memory, unzip it first or read it line by line


 2:34 pm on Feb 14, 2010 (gmt 0)

do u mean to say unzip the file xyz_zip.zip and read the content of xyz.txt and create a new file xyz_copy.txt and the read from xyz_copy.txt line by line.
i am not sure but is there a way in php to unzip the file xyz_zip.zip and save the xyz.txt as a seperate file or do i have to write the data to a new file(xyz_copy.txt ) and save it ?
please note that the zipped version of the file itself is in GBs and this is causing memory to get exhausted.


 2:09 pm on Feb 15, 2010 (gmt 0)

trouble is, if your files are too big for this particular function, then they're too big

maybe using a shell script would work to unzip and chop it up

though if it gets unzipped then you can work through it with php, though you may have to extend max_execution_time

massive files are always a problem, it may take more than one language/script to deal with it

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved