欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
phpexcel導入excel數據到MYSQL數據庫

phpexcel導入excel數據到MYSQL數據庫  

2012-01-11 16:59:01|  分類(lèi): IT技術(shù) |  標簽: |字號 訂閱

//導入文件表單頁(yè)面 index.php

<form name="frm1" enctype="multipart/form-data" action="insertdb.php" method="post">
   <input name="filename" type="file" /><input name="submit" type="submit" value="import" />
</form>

//執行頁(yè)面insertdb.php

<?php
session_start();
header("Content-type:text/html;charset:utf-8");
//全局變量

$succ_result=0;
$error_result=0;
$file=$_FILES['filename'];
$max_size="2000000"; //最大文件限制(單位:byte)
$fname=$file['name'];
$ftype=strtolower(substr(strrchr($fname,'.'),1));
 //文件格式
 $uploadfile=$file['tmp_name'];
 if($_SERVER['REQUEST_METHOD']=='POST'){
     if(is_uploaded_file($uploadfile)){
          if($file['size']>$max_size){
         echo "Import file is too large";
         exit;
         }
          if($ftype!='xls'){
         echo "Import file type is error";
          exit;  
         }
     }else{
     echo "The file is not empty!";
      exit; 
     } 
 }
require("./conn.php");  //連接mysql數據庫

//調用phpexcel類(lèi)庫
require_once 'phpexcel.php';
require_once 'PHPExcel\IOFactory.php';
require_once 'PHPExcel\Reader\Excel5.php';

$objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
$objPHPExcel = $objReader->load($uploadfile);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); // 取得總行數
$highestColumn = $sheet->getHighestColumn(); // 取得總列數
  $arr_result=array();
  $strs=array();

for($j=2;$j<=$highestRow;$j++)
 { 
    unset($arr_result);
    unset($strs);
 for($k='A';$k<= $highestColumn;$k++)
    {
     //讀取單元格
  $arr_result  .= $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue().',';
    }
 $strs=explode(",",$arr_result);
 $sql="insert into student(typeId,name,sex,age) values ($strs[0],'$strs[1]','$strs[2]',$strs[3])";
 echo $sql."<br/>";
 mysql_query("set names utf8");
 $result=mysql_query($sql) or die("執行錯誤");

 $insert_num=mysql_affected_rows();
  if($insert_num>0){
        $succ_result+=1;
    }else{
        $error_result+=1;
   }

}

echo "插入成功".$succ_result."條數據?。?!<br>";
echo "插入失敗".$error_result."條數據?。?!";

?>
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
php利用PHPExcel類(lèi)導出導入Excel用法
PHP導出Excel的類(lèi)庫—PHPExcel,支持附帶圖片
PHP訪(fǎng)問(wèn)MySQL數據庫的幾種方法(轉)
面試題1
PHP連接MySQL數據庫并以json格式輸出
PHP將數組存入數據庫中的四種方式
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久