Object of class mysqli_result could not be converted to string in

1.2K    Asked by CamelliaKleiber in Salesforce , Asked on Jul 6, 2021

I am executing the below code.

$result = mysqli_query($con, "SELECT classtype FROM learn_users WHERE username='abcde'");
echo "my result";

I am getting the following error:

 Object of class mysqli_result could not be converted to string 
Answered by Donna Chapman

 If you are getting Catchable fatal error: Object of class mysqli_result could not be converted to string.

The mysqli_query() method will be returning an object resource to your $result variable, not a string value.

You have to loop it up and then access the records. Because you directly can not use it as your $result variable.

while ($row = $result->fetch_assoc()) {
    echo $row['classtype']."";
}

Your Answer

Interviews

Parent Categories