我有一个看起来像这样的函数,其目的是通过电子邮件检查数据库中是否已存在用户:
function b_check_if_email_exists(mysqli $db_object, $email)
{
$statement = $db_object->prepare("SELECT * FROM users WHERE email = ?");
$statement->bind_param("s", $email);
$statement->execute();
return ($statement->num_rows > 0);
}
但是,由于false
始终为0,函数始终返回$statement->num_rows
。在MySQL Workbench中输入查询SELECT * FROM users WHERE email = "email@user.com"
可以完美地运行。任何帮助将不胜感激。
答案 0 :(得分:1)
尝试:
function b_check_if_email_exists(mysqli $db_object, $email)
{
$statement = $db_object->prepare("SELECT * FROM users WHERE email = ?");
$statement->bind_param("s", $email);
$statement->execute();
$statement->store_result();
return ($statement->num_rows > 0);
}