亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

大數據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.xianlaiwan.cn/video/8527

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

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

舉報

0/150
提交
取消

大數據EXCEL 導入數據庫(50W+), 要怎么處理

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號