I'm having a problem getting a num_row
when I fetch the results as an array:
$sql = "SELECT * FROM people WHERE peopleid=?";
if (!($stmt = $mysqli->prepare($sql))) {
echo "stmt Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("i", $_GET['peopleid'])) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->store_result();
$exist=$stmt->num_rows;
$result = $stmt->get_result();
$peopleres = $result->fetch_array(MYSQLI_ASSOC); // this does work :)
if ($exist == 0) {
//do something it it's zero
}
If I place the store_results and num_rows where it is in the example I get an
Call to a member function fetch_array() on a non-object error.
If I place it after the fetch_array it's always equal to zero. I've used num_rows successfully before, but this is the first time I'm trying to use it alongside a fetch_array.