PHP LOAD DATA INFILE忽略行

时间:2014-03-28 14:21:54

标签: php mysql load-data-infile

我试图在我的数据库中插入.csv文件。我的文件中有大约300k行,但实际上我的表中只插入了5k行。

我做

 //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...

1 个答案:

答案 0 :(得分:0)

实际上,我使用的表没有正确设置主键是一个问题。

我将id列设置为主要列,我更改了包含" A25"的行的排序规则。这解决了我的问题。