<?php
ini_set('display_errors', 1);
// this file must be included only after mysql_connect file

try {
    
    $array_getRegionName_id_array = [];
    $array_getRegionName_name_array = [];

    
    function getRegionName($specific_db_conn,$workspace_id, $company_id, $branch_id, $book_id, $region_id) {
        if(in_array($region_id, $GLOBALS['array_getRegionName_id_array'])) {
            return $GLOBALS['array_getRegionName_name_array'][array_search($region_id, $GLOBALS['array_getRegionName_id_array']).''];
        } else {
             $sql_getRegionName = $specific_db_conn->prepare("Select name from inventory_region_details where workspace_id = ? and company_id = ? and branch_id = ? and book_id = ? and id = ?");
   
            $sql_getRegionName->execute(array($workspace_id, $company_id, $branch_id, $book_id, $region_id));
            $result_getRegionName = $sql_getRegionName->fetchAll();
            if(count($result_getRegionName) == 1) {
                $GLOBALS['array_getRegionName_id_array'][] = $region_id;
                $GLOBALS['array_getRegionName_name_array'][] = ucwords($result_getRegionName[0]['name']);
                return ucwords($result_getRegionName[0]['name']);
            } else {
                errorreturn('Unable to identify region : '.$region_id);
            }
        }
    }

} catch(Exception $e) {
    errorreturn('Error in establishing region details : '.$e->getMessage());
}

?>