作为一种解决方法,我尝试使用此语法将我的csv文件导入到我的数据库表而不是fgetcsv
,因为上传的文件可能非常大。所以我做到了:
$connect = mysql_connect("localhost","root","");
mysql_select_db("dbtest",$connect);
$filename = $file_path;
$sql = "LOAD DATA INFILE '$filename'
INTO TABLE tbltest
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
(@rcode, @pcode, @mcode, @bcode, @ecode, @filetype, @rec_count, @ges_count, @ck_count, @ic_count, @ran_count);" ;
//echo $sql;
mysql_query ($sql,$connect) ;
现在,问题是我的表中没有插入任何内容。当我echo $sql
时,结果如下:
LOAD DATA INFILE 'uploads/testfile.csv' INTO TABLE tbltest FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n' (@rcode, @pcode, @mcode, @bcode, @ecode, @filetype, @rec_count,
@ges_count, @ck_count, @ic_count, @ran_count);
testfile.csv如下所示:
01|01|01|01|0000|FORM1|5|5|5|||||||||
01|01|01|01|0000|FORM2|238|238||||||||||
01|01|01|01|0000|FORM4|0|||||||||||
01|01|01|01|0000|FORM5|1|||||||||||
01|01|01|01|0000|FORM3|3|3||||||||||