0

The error is

Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\posdef\index.php on line 18

Evidently, I perceive that the query returns an object resource, but how to convert it into a string. I am caught up in that problem. How to convert the object resource into string and store it in a variable?

This is the piece of code where I am trying to recover the data stored -

$con = mysqli_connect("localhost", "root", "");
mysqli_select_db($con, "new");
$mylogo = mysqli_query($con, "SELECT first FROM hello WHERE sno=6");
Dharman
  • 30,962
  • 25
  • 85
  • 135

2 Answers2

2

You got the data, now you just need to fetch it:

$con = mysqli_connect("localhost", "root", "");
mysqli_select_db($con, "new");
$mylogo = mysqli_query($con, "SELECT first FROM hello WHERE sno=6"); 

 while ($row = $mylogo->fetch_assoc()) {
   echo $row["first"];
}
meda
  • 45,103
  • 14
  • 92
  • 122
0

Check out the docs, there are additional examples. mysqli_fetch_assoc

Once you run the query, you have to read the results. If you're only expecting ONE row back, you can do the following instead of a while loop:

$rslt = mysqli_query($con, "SELECT first FROM hello WHERE son=6");
$row = $result->fetch_assoc();
$mylogo = $row['first'];
mable
  • 144
  • 7