replace into mysql去重_上传 phpexcel 类 入库并入库前去重
upload.html???頁面
upload.php頁面<?php
require_once?"../upload/PHPExcel_1.8.0_doc/Classes/PHPExcel/IOFactory.php";
$object?=new??PHPExcel();
$filePath?=$_FILES["file"]["tmp_name"];
$fileType?=?PHPExcel_IOFactory::identify($filePath);?//文件名自動判斷文件類型
$objReader?=?PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel?=?$objReader->load($filePath);
$currentSheet?=?$objPHPExcel->getSheet(0);?//第一個工作簿
$allRow?=?$currentSheet->getHighestRow();?//行數
/**取得最大的列號*/
$allColumn?=?$currentSheet->getHighestColumn();
for($rowIndex=2;$rowIndex<=$allRow+1;$rowIndex++){
if($objPHPExcel->getActiveSheet()->getCell("A".$rowIndex)->getValue()){
if($objPHPExcel->getActiveSheet()->getCell("A".$rowIndex)->getValue()){
$hba=strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("A".$rowIndex)->getValue()));
$hbb=strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("B".$rowIndex)->getValue()));
$new_arr[]=
‘(\‘‘.$hba.‘\‘,‘.
"‘".($hbb.‘‘)."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("C".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("D".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("E".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("F".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("G".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("H".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("I".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("J".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("K".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("L".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("M".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("N".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("O".$rowIndex)->getValue()))."‘".‘,‘.
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("P".$rowIndex)->getValue()))."‘".‘,‘.
//strtotime(date(‘Y-m-d?H:i:s‘)).",".
"‘".strtoupper(trim($objPHPExcel->getActiveSheet()->getCell("Q".$rowIndex)->getValue()))."‘".‘)‘;
}
}//此處A-Q表示??表格的列到哪個字母?這里就寫到哪個字母?(根據自身的需求)
mysql_connect("localhost","root","root");
mysql_select_db("count");
mysql_query("SET?AUTOCOMMIT=0");//設置為不自動提交,因為MYSQL默認立即執行
mysql_query("BEGIN");//開始事務定義
mysql_query("set?names?utf8");
foreach($new_arr?as?$vv){
$sql=mysql_query("replace?into?wangyou?(addtime,sp_code,sp_name,yw_code,yw_name,month_payuser,
month_xzuser,day_payuser,day_pay,day_paycs,month_pay,qsst_payuser,content_class,day_paybl,day_syuser,month_syuser,qsst_syuser)?values?$vv");
if(!$sql){
mysql_query("ROOLBACK");//判斷執行失敗回滾
}
}
mysql_query("COMMIT");//執行事務
}
$count=mysql_num_rows(mysql_query("select?*?from?wangyou"));
$chongfu=$allRow-$count-1;
echo?"網游管控成功入庫".$count."條".","."重復".$chongfu."條";
?>
這里的去重????用到了mysql里的唯一索引?unique???當然用到unique時相應的sql就變成replace?into
本文出自 “php開發” 博客,轉載請與作者聯系!
原文:http://872520828.blog.51cto.com/9822540/1604774
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的replace into mysql去重_上传 phpexcel 类 入库并入库前去重的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 甲醇汽车概念股 另类新能源异军突起
- 下一篇: mysql开机启动脚本_centos简单