PHPExcel to insert database using Pg_query

大憨熊 提交于 2019-12-13 07:03:51

问题


I'm using PHP Excel to insert data CSV into database. But i confused to apply it.

Here's Mycode:

<?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
}

?>

But when i tried to insert variable as array of variable, it doesn't work.

The Error :

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

How am i supposed to do?

来源:https://stackoverflow.com/questions/37432748/phpexcel-to-insert-database-using-pg-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!