2014-05-13 104 views
0

嗨,我如何将csv文件插入到数据库中。该表具有以下列。在数据库中使用CSV文件

database: appwarehouse 
table:application table 
column: app_id, app name 

这是我的观点

<form action="<?php echo base_url(); ?>some_controller/uploadBulk" method="post" enctype="multipart/form-data">  
    <label for="exampleInputFile">File Upload</label> 
    <input type="file" name="file" id="file"><br><br> 
    <input type="submit" name="submit" value="Upload" class="classname"><br>    
</form> 

代码这是我的控制器

public function uploadBulk(){ 
    $this->load->model('some_model'); 
    /* 
     * similar to $name = $_POST['name']; 
    */ 
    $file = $this->input->post('file'); 

    $success = $this->some_model->insertBulkApp($file); 
    /* i DONT REALLY KNOW THE CODE JUST INSERT SOME CODE IN HERE */ 

    if($success == TRUE) 
     $this->insert_page(TRUE); 
    else 
     $this->insert_page(FALSE); 
} 

代码,我还需要为我的模型的代码。

回答

0

模型内的代码可以是非常简单的

public function insertBulkApp($file) { 
    // Name of the table you want to insert to 
    $this->db->insert('application table', $file); 
} 

里面你的控制器,你可以设置一个数组,其中键将等于要插入到

// Column name of the table you want to insert to 
$file["app name"] = $this->input->post('file'); 
$this->some_model->insertBulkApp($file); 
表的列名

编辑

你可以去网上查的文档,了解有关笨更多的信息。 Codeigniter documentation

+0

你是什么意思的两个意见? – user3630809

相关问题