我试图只获取返回行的一个值..这里是我尝试过的
function getUserEmail($username) {
global $mysqli;
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM users WHERE username =? LIMIT 1");
$stmt->bind_param("s", $username);
$stmt->execute();
$userEmail = $stmt->fetch_object()->useremail;
return $userEmail;
}
我收到此错误
Fatal error: Call to undefined method mysqli_stmt::fetch_object()
我正在寻找的只是让用户的电子邮件无需获取其他数据。
答案 0 :(得分:1)
mysqli_stmt没有方法fetch_object
,但mysqli_result没有。
见http://docs.php.net/manual/en/mysqli-stmt.get-result.php