我尝试使用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);
}
}