繁体   English   中英

codeigniter更新Excel文件中的数据(数组到字符串的转换)

[英]codeigniter update data from excel file (Array to string conversion)

我尝试使用CodeIgniter从excel文件(.xlsx)更新oracle表中的数据。 我已经上传了excel文件,但是当我尝试更新数据时,出现以下错误消息:

Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1524
Backtrace:

File: C:\xampp\htdocs\web_excel_ci_test\application\models\RoadmapModel.php
Line: 84
Function: update

File: C:\xampp\htdocs\web_excel_ci_test\application\controllers\Roadmap.php
Line: 209
Function: update_data 

控制器:

    function update(){
    $this->load->library('session');
    $fileName = $this->session->flashdata('fileName');
    $fileName2 = $this->session->flashdata('fileName2');

    include APPPATH.'third_party/PHPExcel/PHPExcel.php';
    $excelreader = new PHPExcel_Reader_Excel2007();
    $loadexcel = $excelreader->load('excel/'.$fileName);
    $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);

    $data = [];     
    $numrow = 1;
    foreach($sheet as $row){
        if($numrow > 1){
            array_push($data, [
                'YEAR'=>$row['A'], 
                'PROVINCEID'=>$row['B'], 
                'PROVINCE'=>$row['C'], 
                'PLAN_A'=>$row['D'], 
                'ACTUAL_A'=>$row['E'],

            ]); 
        }
        $numrow++; 
    }
    $year = $this->input->post('YEAR');
    $this->RoadmapModel->update_data($year, $fileName2, $data);
    redirect("Roadmap");
}

模型:

function update_data($year, $fileName2, $data){
    for ($i=0; $i < count($year) ; $i++) {
        $this->db->where('YEAR', $year[$i]);
        $this->db->update($fileName2, $data);
        }
    }

我认为您的$ data是一个多维数组,请尝试使用

$this->db->update_batch

处理批量更新。 您也可以在这里查看更多选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM