广东话上传文件CSV数据库主办

2019年11月26日 43点热度 0条评论 来源: Misdan Wijaya

我有这样广东话上传文件CSV数据库主办

function upload() { 

    $this->db->empty_table('area_proses'); 

    $data['error'] = ''; //initialize image upload error array to empty 

    $config['upload_path'] = './coba_upload/'; 
    $config['allowed_types'] = 'csv'; 
    $config['max_size'] = '20'; 

    $this->load->library('upload', $config); 

    $data['level'] = $this->session->userdata('level_id'); 
    $data['email'] = $this->session->userdata('email'); 
    $data['include'] = $this->load->view('/read/include','',TRUE); 
    $data['content'] = $this->load->view('/read/upload',$data,TRUE); 
    $this->load->view("admin/main",$data); 

    // If upload failed, display error 
    if (!$this->upload->do_upload()) { 
     $data['error'] = $this->upload->display_errors(); 
     //$this->load->view('/read/upload', $data); 
    } else { 
     $file_data = $this->upload->data(); 
     $file_path = './coba_upload/'.$file_data['file_name']; 

     if ($this->csvimport->get_array($file_path)) { 
      $csv_array = $this->csvimport->get_array($file_path); 
      foreach ($csv_array as $row) { 
       $insert_data = array(
        'id'=>$row['id'], 
        'area_proses'=>$row['area_proses'], 
        'sg1'=>$row['sg1'], 
        'sg2'=>$row['sg2'], 
        'sg3'=>$row['sg3'], 
        'avg'=>$row['avg'], 
        'fuzzy'=>$row['fuzzy'], 
       ); 
        $this->model->insert_csv($insert_data); 
       } 
       $this->session->set_flashdata('success', 'Csv Data Imported Succesfully'); 
       redirect(base_url().'area_proses'); 
        //echo "<pre>"; print_r($insert_data); 
     } else 
      $data['include'] = $this->load->view('/read/include','',TRUE); 
      $data['content'] = $this->load->view('/read/upload',$data,TRUE); 
      $this->load->view("admin/main",$data); 
    } 


} 

问题是,我可以上传CSV文件插入到数据库在本地主机(XAMPP),但是当我托管代码,该代码是不行的,只能删除一个数据而不能读取csv插入数据库

你有解决方案吗?

===========解决方案如下:

首先,您应该检查LOAD DATA INFILE以将csv导入到数据库中。 如果您的数据量很大,它比循环更好。

https://dev.mysql.com/doc/refman/5.7/en/load-data.html

    原文作者:Misdan Wijaya
    原文地址: https://stackoverflow.com/q/46852447
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。