simple-mysqli icon indicating copy to clipboard operation
simple-mysqli copied to clipboard

Warning: Trying to access array offset on value of type null in...

Open bogdan2305 opened this issue 10 months ago • 0 comments

This function returns error Warning: Trying to access array offset on value of type null in... if $result is null.

    public function getResult($query, $pos = 0)
    {
        if($query) {
            $results = $this->query($query);
            $result = $results->fetch_array();
            return $result[$pos];
        }
    }

Must be updated:

    public function getResult($query, $pos = 0)
    {

        if($query) {
            $results = $this->query($query);
            $result = $results->fetch_array();
            if($result)
            {
                return $result[$pos]; 
            } 
        } 
    }

bogdan2305 avatar Apr 05 '24 14:04 bogdan2305