'php MS_SQL server resource_id 39 issue

i am accessing my website from another computer in same network. before when i was using localhost on same pc website was working fine when i chnaged that to IP there is a resource id error when we make connection code :

function OpenCon_PI()
{
  /* Database Details */
  $servername = file_get_contents("http://192.168.XX.XX/Project_folder/ipfile.txt");
  
  //for remote connection
  $connectionInfo = array( "Database"=>"Database_name", "UID"=>"local", "PWD"=>"myPassword",'ReturnDatesAsStrings'=>true);
  $conn = sqlsrv_connect( $servername, $connectionInfo);
  //print_r($conn); //when i print this resouce id 39 comes

    return $conn;
}

this is where i call he function it doesnot return any data. an empity array. it was suppose to send large amount of data to plot on graphs

public function getTabularData_DF_COB($startdatetime,$enddatetime,$temperature,$temperature2)
{
    $result_array = array();
    $conn = OpenCon_PI();
    
    if( $conn === false ) {
        die( print_r( sqlsrv_errors(), true));
    }

    if($temperature == "")
    {
        

        $sql = "Select *  FROM Table_name where time >= '$startdatetime' and time <= '$enddatetime'";
        $stmt = sqlsrv_prepare($conn, $sql);
        $data = array();
        $result = sqlsrv_query($conn, $sql);

        if($result === false) {
            die(print_r(sqlsrv_errors(), true));
        }
        #Fetching Data by array
        while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
        {
            array_push($result_array, $row);
        }
        //print_r($result_array);
        return $result_array;
    }else {
        //edit me here

        $sql = "Select * FROM Table_name where time >= '$startdatetime' and time <= '$enddatetime' and ((CAST (fc as float)) BETWEEN '$temperature' AND '$temperature2' ) ";
        $stmt = sqlsrv_prepare($conn, $sql);
        $data = array();
        $result = sqlsrv_query($conn, $sql);

        if($result === false) {
            die(print_r(sqlsrv_errors(), true));
        }
        #Fetching Data by array
        while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
        {

            array_push($result_array, $row);
        }
        return $result_array;

    }

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source