mysqli_result类的对象无法转换为字符串

Here is the code. When I execute it it shows the error message "Catchable fatal error: Object of class mysqli_result could not be converted to string" Please help me to solve this problem.

$sql = "SELECT dname FROM bdonor WHERE DID = 2";
$dname = $con->query($sql);
echo $dname;

you are trying to convert the class mysqli_result to string(obviously it returns error), try this..

$sql = "SELECT dname FROM bdonor WHERE DID = 2";
$result= $con->query($sql);
while($row = $result->fetch_array(MYSQLI_ASSOC))
       echo $row['dname '].'<br />'; // here is the output display line by line

Try this code

function mysqli_result($res,$row=0,$col=0){ 
    $numrows = mysqli_num_rows($res); 
    if ($numrows && $row <= ($numrows-1) && $row >=0){
        mysqli_data_seek($res,$row);
        $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
        if (isset($resrow[$col])){
            return $resrow[$col];
        }
    }
    return false;
}