Solved

CSV Import to MySQL through PHP

Posted on 2009-07-01
6
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24754360
0
 
LVL 5

Expert Comment

by:kingofnines
ID: 24754383
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
ID: 24754443
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24754915
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
ID: 31598770
Awesome!  Thank you
0
 
LVL 110

Expert Comment

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

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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