无法将Excel数据导入Mysql

时间:2019-02-05 13:46:04

标签: mysql phpexcel

我正在按照此网站[https://www.webslesson.info/2018/04/how-to-import-excel-data-into-mysql-database-using-codeigniter.html#comment-form][1]

的步骤进行操作

但是当我尝试导入数据时,我的数据库数据仍然为空

我在Controller中的导入功能:

 public function import()
 {
  if(isset($_FILES["file"]["name"]))
  {
   $path = $_FILES["file"]["tmp_name"];
   $object = PHPExcel_IOFactory::load($path);
   foreach($object->getWorksheetIterator() as $worksheet)
   {
    $highestRow = $worksheet->getHighestRow();
    $highestColumn = $worksheet->getHighestColumn();
    for($row=2; $row<=$highestRow; $row++)
    {
     $customer_name = $worksheet->getCellByColumnAndRow(0, $row)->getValue();
     $address = $worksheet->getCellByColumnAndRow(1, $row)->getValue();
     $city = $worksheet->getCellByColumnAndRow(2, $row)->getValue();
     $postal_code = $worksheet->getCellByColumnAndRow(3, $row)->getValue();
     $country = $worksheet->getCellByColumnAndRow(4, $row)->getValue();
     $data[] = array(
      'CustomerName'  => $customer_name,
      'Address'   => $address,
      'City'    => $city,
      'PostalCode'  => $postal_code,
      'Country'   => $country
     );
    }
   }
   $this->pppmodel->insert($data);
   echo 'Data Imported successfully';
  } 
 }

我的模特:

public function insert($data)
 {
  $this->db->insert('tbl_customer', $data);
 }
}

请帮助我

0 个答案:

没有答案