2012-10-10 59 views
0

我有一個Excel電子表格,我保存爲一個CSV文件。我有一個PHP腳本,我正在使用它將csv導入到mysql數據庫中。我試圖導入它,它會得到一半通過和失敗,經過大量的試驗和錯誤,我發現有時線回報有問題,但我不知道爲什麼。例如,如果你看下面的幾行(圖1),它會運行導入ok,超過20行,到達下面的行並出錯,如果我刪除行返回(圖2),所以2行成爲一行,然後在同一位置添加一行換行(圖3),然後再次運行導入。csv文件導入MySQL與PHP行返回

圖1.

C10940,Design CLOSED,BRAN B,D4072/2,IN000773,IN000773,2003-06-18,GAG,VG232-232AULP,10 
C12261,Newton,CHARLTON G,G4377,IN000908,IN000908,2003-06-18,GAG,VK230-110,31 
C12261,Newton,CHARLTON G,G4377,IN000908,IN000908,2003-06-18,GAG,EB211-130,39 

圖2.

C10940,Design CLOSED,BRAN B,D4072/2,IN000773,IN000773,2003-06-18,GAG,VG232-232AULP,10C12261,Newton,CHARLTON G,G4377,IN000908,IN000908,2003-06-18,GAG,VK230-110,31 
C12261,Newton,CHARLTON G,G4377,IN000908,IN000908,2003-06-18,GAG,EB211-130,39 

圖3.

C10940,Design CLOSED,BRAN B,D4072/2,IN000773,IN000773,2003-06-18,GAG,VG232-232AULP,10 
C12261,Newton,CHARLTON G,G4377,IN000908,IN000908,2003-06-18,GAG,VK230-110,31 
C12261,Newton,CHARLTON G,G4377,IN000908,IN000908,2003-06-18,GAG,EB211-130,39 

回答

0

你可能想簡單地看看MySQL的原生LOAD DATA INFILE

例如

LOAD DATA LOCAL INFILE /path/to/example.csv 
INTO TABLE example_table_name 
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\r\n'