我正在尝试上传包含超过10万行的CSV文件。下面的代码工作正常,但是,它太慢了,我不得不修改php.ini的原因。我正在寻找一种让它更快的方法
mysqli_query($db, "SET AUTOCOMMIT=0");
mysqli_query($db, "BEGIN");
mysqli_query($db, "SET FOREIGN_KEY_CHECKS = 0");
fgets($handle);
$data = '';
while (($data = fgetcsv($handle, 100000, ';')) !== FALSE):
$nf = trim($data[0]);
//ignore values lower than 1
if ($nf < 1):
continue;
else:
$v1 = trim($data[1]);
$v2 = trim($data[2]);
$query = "SELECT * FROM tbl_venda WHERE nota = ". $nf ;
$rs = mysqli_query($db, $query);
validaQuery($db, $rs);
//if $nf alrealdy exists, update, else, insert a new row
if (mysqli_num_rows($rs) > 0):
//UPDATE
else:
//INSERT
endif;
endif;
endwhile;
mysqli_query($db, "COMMIT");
mysqli_query($db, "SET AUTOCOMMIT=1");
mysqli_query($db, "SET FOREIGN_KEY_CHECKS = 1");
mysqli_close($db);
</pre>
<p>Does anyone know how can i make it faster?</p>