PDA

View Full Version : Importing .cvs to MySql database -- phpMyAdmin



Humper
10-26-2006, 08:28 PM
I have a .cvs file that has a list of the building and room numbers
here is what is in the test.cvs file


1 0111A
1 0111B
1 0111C
2 0211A
2 0211B
2 0211C


in the table called room_info it has two fields building and room

when I insert the .cvs file it only inserts the first row of the .cvs file and it only inserts it into the building field... it leaves room blank.... and doesnt go any futher... no errors show up either... what am I doing wrong... I have never tried to import data before so I am lost here.. I tried to add "" around the input but that didnt help.. I also tried adding ; to the end of each line like 1 0111A ; that didnt work either...

BTW room is the primary key... for the table

codeexploiter
10-27-2006, 06:41 AM
Is it .CSV or .CVS. If it is .CSV then you should use comma as the delimeter. If the fields are delimeted using comma then it would look something like the following

1,0111A
1,0111B
1,0111C
2,0211A
2,0211B
2,0211C
3,0789D

If you want to import the data from a .CSV file issue the following command in the SQL Query manager area.


LOAD DATA INFILE 'C:\\test.csv' REPLACE INTO TABLE `test`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'

Here one of the most important point is FIELDS TERMINATED BY ',' if you try to import data which is not delimeted using comma then this will not work.