使CSV上传文件更快(mysql-php)

时间:2013-04-03 16:27:35

标签: php mysql file-upload csv upload


我正在尝试上传包含超过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 &lt 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) &gt; 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>

0 个答案:

没有答案