A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearI'm having a helluva time with data importing (PHP MySQL) - page 1
User InfoPosts
I'm having a helluva time with data importing (PHP MySQL)#1
I'm building an app that pulls data in from an excel .csv file and applying various levels of formatting, moving and mapping. Most everything is figured out except for one hitch with cleaning the data. Here is an example of the data from Excel:


GREAT PERFORMANCES,GREAT PERFORMANCES,57744 ROUND LAKE RD,NEW YORK,NY
"GUASTAVINO'S, INC",GUASTAVINO'S,8250 WESTHEIMER RD,NEW YORK,NY
THE CLARKES GROUP LLC,HUGO'S FROG BAR,915 3RD AVE,CHICAGO,IL
TRIOMPHE RESTAURANT CORP,"GEORGE'S,JEAN",1309 E PUTNAM AVE,NEW YORK,NY


I can't do a straight explode() because of line 3's 2 and 4. There is a "string, string" on both of those lines and I have no control over the data exporting, just cleaning on import.

I've tried a number of non-graceful options and it's killing the processing time. Can anyone think of an elegant solution?

I can't use the MySQL IMPORT functionality, it has to be handled via PHP unfortunately.

posted date: 2008-12-21 14:44:00


Re: I'm having a helluva time with data importing (PHP MySQL)#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-21 14:44:01


Re: I'm having a helluva time with data importing (PHP MySQL)#3
You can also try executing a SQL statement:LOAD DATA INFILE 'mydata.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';I hear you about using PHP, but you can run the statement above from PHP. Or do you mean that the input is a stream resulting from reading CSV, not a CSV file? Unfortunately LOAD DATA INFILE requires a filename, it can't take standard input.

posted date: 2008-12-21 14:52:00


Re: I'm having a helluva time with data importing (PHP MySQL)#4
Didn't he say he wanted to do it with PHP? shakes head

posted date: 2008-12-21 14:55:00


Re: I'm having a helluva time with data importing (PHP MySQL)#5
mysql_query("LOAD DATA INFILE...");

posted date: 2008-12-21 14:57:00


Re: I'm having a helluva time with data importing (PHP MySQL)#6
The point is that you can do this programmatically (from PHP), accomplishing the equivalent of the "mysqlimport" tool.

posted date: 2008-12-21 14:59:00


Re: I'm having a helluva time with data importing (PHP MySQL)#7
OMG my brain hurts. +1 for seeing through the mist.

posted date: 2008-12-21 15:01:00


Re: I'm having a helluva time with data importing (PHP MySQL)#8
I see your question has been answered. But if you wanted to read the file into PHP for use, you could just have used fgetcsv.

posted date: 2008-12-21 17:07:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.