<?php
if (isset($_POST["search"])) {
    include("../connectSQL_Component.php");

    $search = $_POST["search"];
    $file_tables = [];
    $array = [];
    $sql = "SELECT [id],[title], [file_path] FROM [BIMComponents].[dbo].[Video_Table] 
        WHERE [title] like '%".$search."%';";

    $fetchResult = sqlsrv_query($conn, $sql);
    while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
        array_push($file_tables, $row);
    }

    $array["file_tables"] = $file_tables;

    echo json_encode($array);

    sqlsrv_close($conn);
}
