0

我已经尝试了一段时间来num_rows()返回一个值。我最近开始在 mysqli 中使用 OO 样式,但我不知道为什么它没有回显行数。

if ($statement = $db -> prepare("SELECT first_name, second_name FROM accounts WHERE email=? AND password=?"))
{
    $email = trim($_GET['email']);
    $password = crypt(trim($_GET['password']),"H7qb4lDy8u8719v1H663694sHF972mt265tk108p");
    $statement -> bind_param("ss", $email, $password);
    $statement -> execute();
    $statement -> bind_result($result);
    $statement -> fetch();
    echo $result->num_rows;
    $statement -> close();
    $db -> close();
}
4

1 回答 1

1

这是因为您正在使用echo $result->num_rows;而您应该使用echo $statement->num_rows;using object

手动示例

$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
if ($stmt = $mysqli->prepare($query)) {

    /* execute query */
    $stmt->execute();

    /* store result */
    $stmt->store_result();

    printf("Number of rows: %d.\n", $stmt->num_rows);
                                  //^^using object
于 2013-06-08T14:50:49.610 回答