<?php

if(isset($_POST["action"])){    
require('../config/dbcon.php');
if($_POST["action"] == "noofrow_mst"){
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 = ('noofrow_mst.xlsx');
$reader = ReaderFactory::create(Type::XLSX);
$reader->open($filePath);
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
$result = $connect->query("DELETE FROM noofrow_mst");
if (($extension == 'xlsx' || $extension == 'xls')){
$count = 0;
	foreach ($reader->getSheetIterator() as $sheet){
		foreach ($sheet->getRowIterator() as $row){
			if($count > 0){
				$description = $row[0];
				$noofrow = $row[1];
				$qry = "INSERT INTO noofrow_mst(description,noofrow) VALUES ('$description','$noofrow')";
				$result = $connect->query($qry);
			}
			$count++;
		}
	}
}
$reader->close();
header ("Location: index.php");
}
}
//====================================================================
?>
