Solved

CSV Import to MySQL through PHP

Posted on 2009-07-01
6
306 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Technology Partners: 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!

Question has a verified solution.

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

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 i…
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…
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.

707 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