1

why always $stmt->num_rows returns 0(zero), Whereas exist 2 records in users table. code:

    public function fetch_users()
    {
        if (!($stmt = $this->mysqli->prepare("SELECT * FROM users"))){
            echo "prepare failed: (" . $this->mysql->errno . ") " . $this->mysqli->error;
        }

        if (!$stmt->execute()) {
            echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
        }

        echo $stmt->num_rows;
    }
4

1 回答 1

0

解决了这个变化:

public function fetch_users()
{
    if (!($stmt = $this->mysqli->prepare("SELECT * FROM users"))){
        echo "prepare failed: (" . $this->mysql->errno . ") " . $this->mysqli->error;
    }

    if (!$stmt->execute()) {
        echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
    }

    $stmt->store_result();

    echo $stmt->num_rows;
}
于 2013-01-16T18:10:30.273 回答