Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-如何更快地导入200k数据?还有';s403错误_Php - Fatal编程技术网

PHP-如何更快地导入200k数据?还有';s403错误

PHP-如何更快地导入200k数据?还有';s403错误,php,Php,如何更快地导入200k数据 当我使用online导入csv(逗号分隔)文件时,我得到了403个错误,它只插入了200-400个数据。另外,当我尝试使用localhost(xampp)导入它时,我得到了 “模块xampp-control.exe中001AA712处的异常EAccessViolation 模块“xampp control.exe”中地址005AA712处的访问冲突 读取地址00000042“ SQL数据库连接也消失了 这是我使用的代码 set_time_limit(0

如何更快地导入200k数据

当我使用online导入csv(逗号分隔)文件时,我得到了403个错误,它只插入了200-400个数据。另外,当我尝试使用localhost(xampp)导入它时,我得到了

“模块xampp-control.exe中001AA712处的异常EAccessViolation

模块“xampp control.exe”中地址005AA712处的访问冲突

读取地址00000042“

SQL数据库连接也消失了

这是我使用的代码

        set_time_limit(0);
        ignore_user_abort(true);

        $file = $_FILES['file']['name'];
        $type = $_FILES['file']['type'];
        $size = $_FILES['file']['size'];
        $temp = $_FILES['file']['tmp_name'];
        $error = $_FILES['file']['error'];

        if( ! $file)
        {
            $data['error'] = "Please select a file!";
        }
        else if($type != "application/vnd.ms-excel" && $type != "application/octet-stream")
        {
            $data['error'] = "Invalid file type!";
        }
        else
        {
            $newname = $file." - ".date("Ymd His");
            move_uploaded_file($temp, "uploads/".$newname);
            $fieldseparator = ",";
            $lineseparator = "\n";
            $csvfile = "uploads/".$newname;

            if( ! file_exists($csvfile))
            {
                echo "File not found. Make sure you specified the correct path.\n";
                exit;
            }
            $file = fopen($csvfile,"r");

            if( ! $file)
            {
                echo "Error opening data file.";
                exit;
            }

            $size = filesize($csvfile);
            if(!$size)
            {
                echo "File is empty.";
                exit;
            }
            $csvcontent = fread($file,$size);
            fclose($file);

            $row = 1;
            $data_imported = 0;
            $file3 = fopen($csvfile,"r");
            $total_file_count = (count(file(FCPATH."/".$csvfile)) - 2);

            $i = 0;
            $insert = "INSERT IGNORE INTO `invoice` 
            (`row1`,
                .
                .
                to
                .
                .
             `row33`
            ) VALUES ";

            while($datas = fgetcsv($file3, 10000, ","))
            {
                $i++;
                ob_implicit_flush(true);
                if($row == 1)
                {
                    // Ignore 1st line
                }
                else
                {
                    $row1 = isset($datas[0]) ? $datas[0] : "";
                    .
                    .
                    to
                    .
                    .
                    $row33 = isset($datas[32]) ? $datas[32] : "";

                    if($i == 200 OR $total_file_count == $data_imported)
                    {
                        $insert .= "(
                            '".mysqli_real_escape_string($this->db->conn_id(),$row1)."',
                            .
                            .
                            to
                            .
                            .
                            '".mysqli_real_escape_string($this->db->conn_id(),$row33)."'
                        );";
                    }
                    else
                    {
                        $insert .= "(
                            '".mysqli_real_escape_string($this->db->conn_id(),$row1)."',
                            .
                            .
                            to
                            .
                            .
                            '".mysqli_real_escape_string($this->db->conn_id(),$row33)."'
                        ),";
                    }

                    if($i == 200 OR $total_file_count == $data_imported)
                    {
                        $this->QModel->query($insert);
                        $i=0;
                        $insert = "INSERT IGNORE INTO `invoice` 
                            (`row1`,
                                .
                                .
                                to
                                .
                                .
                             `row33`
                            ) VALUES ";
                    }

                    $data_imported++;
                }
                $row++;
            }
            fclose($file3);

            echo "Success imported ".number_format($data_imported)." data.";
有什么想法吗


谢谢。

您已经有了一个CSV文件,因此可以使用
加载数据填充
@Sirko-加载数据填充效果非常好!它在2-5秒内插入了200k数据,谢谢。