PHP Error Object of class mysqli could not be converted to string in

Write a PHP encountered an error: the Object of the class mysqli could not be converted to a string
An object of class mysqli_result cannot be converted to a string
Check the code:

    function query($sql){
        echo $sql;
        $query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
    
        return $query;
    }

Mysqli_result is returned by mysqli_query, so the error should be on the return value.

You cannot directly output an object as a string in PHP5 above.
So just change the type of the return value.

    function query($sql){
        echo $sql;
        $query = mysqli_query(self::$con,$sql)or die(mysqli_error(self::$con));
        return  mysqli_fetch_array($query);
        //return $query;
    }

Returns as an array with the mysqli_fetch_array() function.

 

Read More: