use*_*211 3 php mysql sql select count
我收到错误:
Object of class mysqli_result could not be converted to string.
Run Code Online (Sandbox Code Playgroud)
码:
<?php
$con=mysqli_connect("78.46.51.231","root","","multicraft_daemon");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = ("select sum(`memory`) from `server`;");
$result = mysqli_query($con, $sql);
echo $result; //$result is mysqli_result and can't be forced to string.
?>
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
bwo*_*ebi 12
您无法直接输出查询结果.使用:
$sql = ("select sum(`memory`) AS memTotal from `server`");
// Show used memory
$result = mysqli_query($con, $sql);
echo $result->fetch_object()->memTotal;
Run Code Online (Sandbox Code Playgroud)
该$result变量包含一个对象(类型为mysqli_result),您可以从中获取需要输出的标量.
| 归档时间: |
|
| 查看次数: |
18821 次 |
| 最近记录: |