嗨,我有一个参数化查询,我正在尝试执行并从中获取最佳结果。当我有我的user_id where子句时,尽管第一行匹配,但没有返回任何结果。我的语法某种程度上是错误的,但是我看不出问题出在哪里。
因此返回结果:
$stmt = mysqli_stmt_init($conn);
$stmt = $conn->prepare("SELECT member_id, company_name FROM member");
$execute_result = $stmt->execute();
if (!$execute_result)
{
throw new Exception("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
}
$stmt->bind_result($col_member_id, $col_company_name);
if ($stmt->fetch())
{
$_SESSION['member_id'] = $col_member_id;
$_SESSION['company_name'] = $col_company_name;
}
$stmt->close();
但这不是:
$stmt = mysqli_stmt_init($conn);
$stmt = $conn->prepare("SELECT member_id, company_name FROM member WHERE userid=?");
$bind_result = $stmt->bind_param("s", $userid);
$execute_result = $stmt->execute();
if (!$execute_result)
{
throw new Exception("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
}
$stmt->bind_result($col_member_id, $col_company_name);
if ($stmt->fetch())
{
## Doesn't come in here for some reason
$_SESSION['member_id'] = $col_member_id;
$_SESSION['company_name'] = $col_company_name;
}
$stmt->close();
有什么想法吗?
答案 0 :(得分:0)
按照@NigelRen的答案,查询是正确的,但输入值不是预期的值。