Solved

CSV Import to MySQL through PHP

Posted on 2009-07-01
6
300 Views
Last Modified: 2013-12-13
I love PHPMyAdmin, but I want something a little more "secure" that I can setup for an average user.  Even something that will import a file from the same location over and over by pressing a button.

The file is CSV file with one strange twist.  One field has several filenames separated by | though like I said, it is a single field called attachments.

Anyone know of any software or good script to modify that could provide this functionality?
0
Comment
Question by:hydrazi
6 Comments
 
LVL 14

Expert Comment

by:shobinsun
Comment Utility
0
 
LVL 5

Expert Comment

by:kingofnines
Comment Utility
it is a fairly easy proccess to parse a CSV file into its seperate fields and then upload them to a table. Take a look at the explode() function...

http://us3.php.net/manual/en/function.explode.php

Using explode() you can  parse your CSV record into an array. Then traverse the array in a loop and build your upload statement. Post a sample of your file and I will write a quick example script.


Alan
0
 
LVL 5

Expert Comment

by:kingofnines
Comment Utility
The second article shobinsun gave you is an example of what I was saying. I didn't see he had posted before I posted.


Alan
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
PHP has a built-in function that may be helpful:
http://nl3.php.net/manual/en/function.fgetcsv.php

You can isolate the filenames that are "pipe-delimited" and get an array with this sort of thing.  The trim() is there in case you get stray whitespace.
http://nl3.php.net/manual/en/function.explode.php

HTH, ~Ray
<?php

$attch = 'file.one|file.two | file.tre| file.for';

$array = explode('|', $attch);

foreach ($array as $pointer => $thing) { $array[$pointer] = trim($thing); }

var_dump($array);

Open in new window

0
 

Author Closing Comment

by:hydrazi
Comment Utility
Awesome!  Thank you
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks for the points!  It's a good question. ~Ray
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now