Mysqli表现出一种奇怪的行为。对于我尝试的任何查询,num_rows始终为0.
$email = trim(mysqli_real_escape_string($con1,$_POST['email']));
$pwd = trim(mysqli_real_escape_string($con1, $_POST['pwd']));
$result = $con1->prepare("select login.email,login.pwd from login
where email = ?");
if(!$result)
{
echo("error");
}
$result->bind_param('s',$email);
$result->execute();
print_r($result); //num_rows is zero
if($result->num_rows > 0)
{
$result->bind_result($email1,$pwd1);
$result->store_result();
while($result->fetch())
{
echo("Email: ".$email1);
}
}
答案 0 :(得分:0)
试试这个:
$email = trim(mysqli_real_escape_string($con1,$_POST['email']));
$pwd = trim(mysqli_real_escape_string($con1, $_POST['pwd']));
$result = $con1->prepare("select login.email,login.pwd from login
where email = ?");
if(!$result)
{
echo("error");
}
$result->bind_param('s',$email);
$result->execute();
$num_row = $result->num_rows;
print_r($num_row); //num_rows is zero
if($num_row > 0)
{
$result->bind_result($email1,$pwd1);
$result->store_result();
while($result->fetch())
{
echo("Email: ".$email1);
}
}
答案 1 :(得分:0)
我们必须在调用num_rows
之前存储结果$stmt->store_result();