php-不能打印mysqli_result

时间:2014-10-27 19:08:08

标签: php mysql

我无法回应我的mysql查询的结果。 PHP代码是:

$getc = "SELECT credits FROM members WHERE Phone ='".$_SESSION['Phone']."'";
$credits = mysqli_query($dbc,$getc);
echo "YOU HAVE $credits CREDITS LEFT";

但是上面显示了以下错误: 可捕获的致命错误:类mysqli_result的对象无法在第204行的file.php中转换为字符串

出了什么问题?

1 个答案:

答案 0 :(得分:1)

您只是在执行查询而不是获取结果,mysqli_query()会返回mysqli_result而不是字段的值

$getc = "SELECT credits FROM members WHERE Phone ='".$_SESSION['Phone']."'";
$result = mysqli_query($dbc,$getc);
$row = mysqli_fetch_assoc($result);
echo "You have {$row['credits']} left!";