PHP and MySQL error: Object of class mysqli_result could not be converted to string

后端 未结 2 1393
小鲜肉
小鲜肉 2020-12-17 06:00

I am getting the error:

Object of class mysqli_result could not be converted to string.

Code:



        
相关标签:
2条回答
  • 2020-12-17 06:40

    You cannot directly output the result of a query. Use:

    $sql = ("select sum(`memory`) AS memTotal from `server`");
    // Show used memory
    $result = mysqli_query($con, $sql);
    echo $result->fetch_object()->memTotal;
    

    The $result variable holds an object (of type mysqli_result), from which you can fetch the scalars you need to output.

    0 讨论(0)
  • 2020-12-17 06:44

    $result is a result object. From thje manual for mysqli_query():

    Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

    0 讨论(0)
提交回复
热议问题