<?php
include("./script/php/permission/connect_sql.php");
include("./script/php/excel/read_excel.php");

$data = $excelData["工作表1"];

for ($i = 1; $i < count($data); $i++) {    
    $sql = "INSERT INTO [21000X].[dbo].[Project_Table_Test]
               ([year]
               ,[projectID]
               ,[projectName]
               ,[department]
               ,[technician]
               ,[engineer]
               ,[proprietor]
               ,[projectDate])
         VALUES
               (?,?,?,?,?,?,?,?);";
    $stmt = sqlsrv_query($conn, $sql, array($data[$i][0],$data[$i][1],$data[$i][2],$data[$i][3],$data[$i][4],$data[$i][5],$data[$i][6],$data[$i][7]));

}
if ($stmt === false) {
    if (($errors = sqlsrv_errors()) != null) {
        foreach ($errors as $error) {
            echo "SQLSTATE: " . $error['SQLSTATE'] . "<br />";
            echo "code: " . $error['code'] . "<br />";
            echo "message: " . $error['message'] . "<br />";
        }
    }
}else{
    echo('success');
}