<?php
   // require_once("vendor/autoload.php");

    $c = mysqli_connect("localhost", "cp360794", "Computer@2023", "cp360794_Norntern");
    mysqli_query( $c, "SET NAMES UTF8" );    

    $xlsx = "fruit.xlsx";
    $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load( $xlsx );
    $v = $spreadsheet->getSheet(0)->toArray();
    foreach($v as $key=>$data) {
        
        if( $key > 0 ) {

            $sql = " INSERT INTO fruit ( id, title ) VALUES ( NULL, '{$data[1]}' ) ";
            $q = mysqli_query( $c, $sql );
            if( $q ) {
                echo "<div>เพิ่มข้อมูล {$data[1]} ลงในตาราง fruit เรียบร้อย</div>";
            } 

        }
    }

    mysqli_close( $c );
    
    

?>