<?php
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;
$connect = new PDO('pgsql:host=localhost;dbname=postgres', 'postgres', 'Kaushik@1610');
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
require_once ('Spout/Autoloader/autoload.php');
//====================================================================
$filePath = ('custsegment_mst.xlsx');
$reader = ReaderFactory::create(Type::XLSX);
$reader->open($filePath);
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
$result = $connect->query("DELETE FROM custsegment_mst");
if (($extension == 'xlsx' || $extension == 'xls')){
$count = 0;
	foreach ($reader->getSheetIterator() as $sheet){
		foreach ($sheet->getRowIterator() as $row){
			if($count > 0){
				$customer_code = $row[0];
				$segment = $row[1];
				$qry = "INSERT INTO custsegment_mst(customer_code,segment) VALUES ('$customer_code','$segment')";
				$result = $connect->query($qry);
			}
			$count++;
		}
	}
}
$reader->close();
header ("Location: index.php");
//====================================================================
?>
