所以,我有一份准备好的陈述,我已成功准备,装订和执行:
401 Unauthorized
看起来像预期的那样返回了一行。但是,当我调用@ SELECT * FROM users WHERE email = ? AND pass = SHA1(?)
时,为什么$ result变量为空?提前谢谢。
$stmt->get_result()
答案 0 :(得分:2)
将这两条评论放在一起并详细说明......
<?php
$result = $stmt->get_result();
$num_rows = mysqli_num_rows($result);
if ($num_rows == 1) {
// already fetched the mysqli_result
// now lets fetch the one record from that result set
$row = $result->fetch_assoc();
// ....do something with row
}
else {
// either 0 ...or more than 1 row
foo();
}
但你甚至可以摆脱对mysqli_num_rows()的调用(所以它也适用于unbuffered queries)
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ( !$row ) {
// no such record
foo();
}
else {
// ....do something with row
// might want to check whether there are more matching records
// given the context there shouldn't, but ...
}