0

我正在使用PHP Excel将数据CSV插入数据库。但我很困惑应用它。

这是我的代码:

<?php 
session_start();
include 'connect.php';
include 'PHPExcel/Classes/PHPExcel/IOFactory.php';
$input=$_POST['times'];
$rev=$_POST['rev'];
$chan=$_POST['channel'];
$uploadid='UP'.$_POST['number'];
$fcid = 'FC'.$_POST['number'];
$schid = 'SCH'.$_POST['number'];
$file = $_POST['filename'];
$inputFileName = 'D:/ForecastCapacity/'.$file;
echo($input.'/'.$rev.'/'.$chan.'/'.$uploadid.'/'.$file);
//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
//  Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestDataColumn();
// $cekk = pg_query("SELECT COUNT (inputtime) From FC WHERE InputTime = '$input'");
// $row = pg_fetch_array($cekk);
// $total = $row[0];
for ($row = 1; $row <= $highestRow; $row++){ 
    //  Read a row of data into an array
    $rowDatabln = $sheet->rangeToArray('A' . $row . ':' . 'A' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
        $rowDatatgl = $sheet->rangeToArray('B' . $row . ':' . 'B' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
         $rowDatajam = $sheet->rangeToArray('C' . $row . ':' . 'C' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
         $rowDatafc = $sheet->rangeToArray('D' . $row . ':' . 'D' . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
    $eva = pg_query("INSERT INTO FC VALUES('$fcid','$schid','$uploadid','$input','$chan','$rowDatabln[$row]','$rowDatatgl[$row]','$rowDatajam[$row]','$rowDatafc[$row]',NULL,'ForecastCapacity');");

    //  Insert row data array into your database of choice here
}

?>

但是当我尝试将变量作为变量数组插入时,它不起作用。

错误 :

Parse error: syntax error, unexpected ']', expecting identifier
(T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in 
C:\xampp\htdocs\SchedulingApplication\Code\dosavecapacity.php on line 47

我该怎么办?

4

0 回答 0