dongqin1075 2013-05-21 09:26
浏览 50

我应该使用ajax将大型csv文件导入mysql数据库吗?

there is a large csv file need to be import to mysql database
there are to ways bellow

1 , upload this csv file using a php then

<?php
$row = 1;
$handle = fopen("test.csv","r");
while ($data = fgetcsv($handle, 1000, ",")) {
    // record rows to to database
}
fclose($handle);
?> 

this way is easy ,but waiting for a long time

2, upload this csv file using a php
then use ajax to record each row of the csv and output the ajax feedback

<script type="text/javascript">
    var row =0;
    $.ajax({
        url:"csv_to_db.php",    //record only one row
        type:"POST",
        data:{
            row : row;
        },
        success:function(){
            row++;
        }
    });
</script>

this way can see the active feedback ajax info ,and the browser will not die when the method 1 wait too long time
but this way will excute fgetcsv function in "scv_to_db.php" every time, seems waiting the cpu and memery

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大