0
我試圖在我的數據庫中插入.csv文件。我的文件中有大約30萬行,但實際上只有5K行插入到我的表中。PHP LOAD DATA INFILE忽略行
我做
//Create a table like the one actually holding the same data
$tmp_table_query = "CREATE TABLE test LIKE Model;";
\DB::connection()->getpdo()->exec($tmp_table_query);
//Insert data in it
$query = sprintf("LOAD DATA local INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 0 LINES", addslashes($file));
\DB::connection()->getpdo()->exec($query);
這裏是我的數據樣本。插入兩個第一行,但不是最後兩個
//Some data...
161041,12/8/2013 13:28:23,"A5",1,150,8009892,9792108,-1,9792108,5000,0,0,0,500,9797108,0,9797534,3,3,424,1,0,0,9797535,1425,-1,-1,0,0,0,0,0
161042,12/8/2013 13:28:23,"A5",1,151,8009892,9798962,9808807,9798962,5000,0,0,0,-1,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,9803807,5000,1,0,0,0,0
161043,12/8/2013 14:00:48,"A25",1,1,9881742,9882184,-1,9882184,5000,0,0,0,500,9887184,0,9887995,1,1,809,1,0,0,9887996,1329,-1,-1,0,1,0,0,0
161044,12/8/2013 14:00:48,"A25",1,2,9881742,9889327,-1,9889327,5000,0,0,0,500,9894327,0,9895199,0,0,870,1,0,0,9895200,1616,-1,-1,0,0,1,1,0
//Some more data...
包含'show create table test'的結果;' – fancyPants
不確定這是否有問題,但是您有'LINES TERMINATED BY'\\ r \ n'';爲什麼'\\ r'額外的反斜槓? – newfurniturey
嗯,它可能只是該查詢需要太長的時間來執行,並在超時情況下失敗,無論PHP執行是否執行查詢...... –