473,467 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Import from csv file to MySQL

Hi,

I'm in the middle of writing a script to import a csv file into mySQL
(as apart of a bigger project)

I need to know what are the best steps to go from $_FILES to file().

Once the file is read into an array I should be right. I don't want to
keep a copy of the file uploaded either, as once it is imported I will
have no use for it.

I'm not sure, do I copy it store it then use it or is there a faster
way? Will the temp file be deleted or do I have to delete it?

Sep 21 '05 #1
2 1915
I am at work so I cant give you the code but what you need to do is the
following:

1. upload to a temporary directory (say /temp - this folder will need
to have appropriate access rights)

2. use the file_read funcions (look for tutorials on flat files for all
this)

3. import your data into the DB

4. If successful use unlink($file); to delete OR print error message

Thanks
Chris

Smitro wrote:
Hi,

I'm in the middle of writing a script to import a csv file into mySQL
(as apart of a bigger project)

I need to know what are the best steps to go from $_FILES to file().

Once the file is read into an array I should be right. I don't want to
keep a copy of the file uploaded either, as once it is imported I will
have no use for it.

I'm not sure, do I copy it store it then use it or is there a faster
way? Will the temp file be deleted or do I have to delete it?


Sep 21 '05 #2
I think I've worked it out, I'm in the middle of writing the script.

I upload the file into $_FILES

grab the temp directory and temp file name etc from $_FILES

then run the mysql_query () something along the lines of "LOAD DATA
INFILE '$file_location' INTO TABLE tale_name etc...

I guess it's one of these things, if you look hard enough you'll find
an answer.

Thanks anyway.

Sep 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: adrian GREEMAN | last post by:
When I try to import a text file with new data for an existing table I get the error "1148 - the used command is not allowed with this MySQL version." I have tried with both PHPMyAdmin2.3 and...
7
by: jj | last post by:
It's taking forever to upload 400,000 records to the database through access/odbc, and I've tried phpMyAdmin's interface but it seems to timeout during import of a CSV file. Is there a better way...
8
by: Johnny | last post by:
I was looking for information on how to import an excel file or other text file into a MySql database. I have done this with both access and SQL Server and am looking for a way to do this in...
2
by: jet | last post by:
Hi, Maybe this is an easy task, but I'm having a really hard time figuring out how to do this. I'm a complete newbie to SQL Server. I have a database dump file from MySQL that's in .sql...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
5
by: Kajol | last post by:
Hi All, can u plz tell me how to import data from mysql to another database. & how to export data from anotherdata base to mysql Thanx for ur Advice Regards Kajol
3
by: Daedalus.OS | last post by:
Hi, I've been asked to transfert a database from a webhoster to another. I think the database is on a windows box but I'm not 100% shure. The webhoster says it provides combined hosting on...
10
by: Avi | last post by:
Hi I need to read in a large set of text files (9GB+ each) into a database table based on fixed width lengths. There are several ways to complete this, but I am wondering if anyone has...
0
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer...
7
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.