开发者社区> 问答> 正文

Laravel maatwebsite Excel包导入2000多个行导致1390代码错误

我有4个excel文件,每个文件包含1000行。我将其合并为4000,这样可以节省一些时间。但是,如果我导入合并的文件,它将返回的错误General error: 1390 Prepared statement contains too many placeholders。但是,当我将它们一一插入时,它可以工作。我不知道为什么会返回这样的错误,它们甚至在每一列中都具有相同的值。有人可以告诉我该错误怎么办吗?需要帮助。非常感谢

我正在使用laravel maatwebsite excel软件包。

我的导入代码

    {
        if($request->hasFile('template')){
            $path = $request->file('template')->getRealPath();
            $data = \Excel::load($path)->get();

            if($data->count() > 0){
                $rows = $data->toArray();

                foreach ($rows as $row) {

                    $level = '';
                    $stack = '';
                    $unit = '';
                    $gunit = '';


                    $street = '';
                    $block_unit = '';

                   //DONT MIND THIS FUNCTION HERE
                    if (strpos($row['address'], '#') !== false) {
                        $unit = explode("#",$row['address']);
                        $gunit = $unit[1];
                        $block = explode(" ",$unit[0],2);
                        if(isset($unit[1])) {
                            $x = explode("-",$unit[1]);
                            $level = $x[0];
                            $stack = $x[1];    
                            $street = $block[1];
                            $block_unit= $block[0];                     
                        }
                    }
                    elseif(strpos($row['address'], ' ') !== false){
                        $unit = explode(" ",$row['address']);
                        $block = explode(" ",$unit[0],2);
                        if(isset($unit[1])) {
                            $x = explode("-",$unit[1]);
                            $level = '';
                            $stack = '';
                            $x = preg_replace('/[0-9]+/', '', $row['address']);
                            $street = $x.substr($street,1);
                            $block_unit= $block[0];      
                        }
                    }
                    else{
                        $level = '';
                        $stack = '';
                        $unit = '';
                        $gunit = '';
                        $block_unit = '';
                        $street = '';
                    }
                    //END

                    $inserts[]=[
                        'transtype' => 'RESI',
                        'project_name' => $row['project_name'],
                        'unitname' => $gunit,
                        'block' => $block_unit,
                        'street' => $street,
                        'level' => $level,
                        'stack' => $stack,
                        'no_of_units' => $row['no._of_units'],
                        'area' => $row['area_sqm'],
                        'type_of_area' => $row['type_of_area'],
                        'transacted_price' => $row['transacted_price'],
                        'nettprice' => $row['nett_price'],
                        'unitprice_psm' => $row['unit_price_psm'],
                        'unitprice_psf' => $row['unit_price_psf'],
                        'sale_date' => $row['sale_date'],
                        'contract_date' => $row['sale_date'],
                        'property_type' => $row['property_type'],
                        'tenure' => $row['tenure'],
                        'completion_date' => $row['completion_date'],
                        'type_of_sale' => $row['type_of_sale'],
                        'purchaser_address_indicator' => $row['purchaser_address_indicator'],
                        'postal_district' => $row['postal_district'],
                        'postal_sector' => $row['postal_sector'],
                        'postal_code' => $row['postal_code'],
                        'planning_region' => $row['planning_region'],
                        'planning_area' => $row['planning_area'],
                    ];
                }


            }

            if(empty($inserts)){
                dd('Request data does not have any files to import.');  
            }
            else {
                \DB::table('xp_pn_ura_transactions')->insert($inserts);
                dd('record inserted');  
            }

        }
    }

展开
收起
社区秘书 2019-12-09 16:45:26 986 0
0 条回答
写回答
取消 提交回答
问答分类:
PHP
问答地址:
问答排行榜
最热
最新

相关电子书

更多
附件下载测试 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载