简体   繁体   中英

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

I'm try to update data in oracle table from excel file (.xlsx) use CodeIgniter. I've already uploaded the excel file but when I try to update the data I get the following error message:

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 

Controller:

    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");
}

Model:

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

i think your $data is a multidimentional array, try to use

$this->db->update_batch

to process batch update. You can also look here to for more options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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