Importing bulk existing data into separate existing sql db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Importing bulk existing data into separate existing sql db

Post by simonmlewis »

I have an Access file, and a MySQL database.

I need to import that data from the Access table into the existing MySQL table.

Some fieldnames differ, but I can alter them in Access before I do anything.

I'm assuming it's be some kind of "INSERT" query, but I've never done it with a bulk of existing data into a query.

Can anyone help please?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Importing bulk existing data into separate existing sql db

Post by aceconcepts »

Hi Simon,

First of all you'll need to be able to read the Access file from PHP right? - Is this how you were thinking about doing it?
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: Importing bulk existing data into separate existing sql db

Post by deejay »

I think fgetcsv is what you need to find out about. http://uk2.php.net/manual/en/function.fgetcsv.php

Something like

Code: Select all

 
$handle = fopen ("document.csv","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
 
// then make an insert
}
 
you could make a new mysql table and then design some sort of filter to put the right fields in your existing database.

Hope this helps
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Importing bulk existing data into separate existing sql db

Post by aceconcepts »

I've used fgetcsv() numerous time before and it has always worked out perfectly.
Post Reply