为了账号安全,请及时绑定邮箱和手机立即绑定

大数据EXCEL 导入数据库(50W+), 要怎么处理

       if (!empty($_FILES)) {

$config = array(

'exts' => array('xlsx','xls'),

'maxSize' => 134217728,

'rootPath' =>"./Public/",

'savePath' => 'Uploads/',

'subName' => array('date','Ymd'),

);

           $upload = new \Think\Upload($config);

           if (!$info = $upload->upload()) {

$this->error($upload->getError());

}

           vendor("PHPExcel.PHPExcel");

$file_name=$upload->rootPath.$info['photo']['savepath'].$info['photo']['savename'];

$extension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));//判断导入表格后缀格式

if ($extension == 'xlsx') {

$objReader =\PHPExcel_IOFactory::createReader('Excel2007');

$objPHPExcel =$objReader->load($file_name, $encode = 'utf-8');

} else if ($extension == 'xls'){

$objReader =\PHPExcel_IOFactory::createReader('Excel5');

$objPHPExcel =$objReader->load($file_name, $encode = 'utf-8');

}

$sheet =$objPHPExcel->getSheet(0);

$highestRow = $sheet->getHighestRow(); //取得总行数

$highestColumn =$sheet->getHighestColumn(); //取得总列数

                    //sql拼接

                    $sql = "INSERT INTO `song_sheet` (`song_no`, `song_name`, `singer_name`, `language`, `film_classification`, `dance_category`, `music_classification`, `epidemic_classification`, `picture_type`, `max_volume`, `song_count`, `backup_information`, `picture`, `retain`, `retain_date`) VALUES ";


for ($i = 2; $i <= $highestRow; $i++) {

                      

                        //拼接

                        $sql .= "('".addslashes($objPHPExcel->getActiveSheet()->getCell("B" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("C" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("D" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("E" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("F" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("G" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("H" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("I" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("J" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("K" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("L" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("M" .$i)->getValue())."',"

                              . "'".addslashes($objPHPExcel->getActiveSheet()->getCell("N" .$i)->getValue())."',"

                              . "'".$objPHPExcel->getActiveSheet()->getCell("O" .$i)->getValue()."',"

                              . "'".$objPHPExcel->getActiveSheet()->getCell("P" .$i)->getValue()."'"

                              . "),";

           }

                    $sql  = substr($sql,0,strlen($sql)-1); 

                    $sql .=";";

                    // print_r(array($sql));exit;

                    $Model = new \Think\Model();

                    $Model->execute($sql);

$this->success('导入成功!',U('Songsheet/index'));die;

       }else{

$this->success('请选择上传的文件!');die;

       }


正在回答

1 回答

参照http://www.imooc.com/video/8527

http://static.mukewang.com/img/59b0b3c90001c34612100716.jpg

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

大数据EXCEL 导入数据库(50W+), 要怎么处理

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信