I want to validate if a query receives a record or not, and for that I am using num_rows, but it always detects 0 rows. But I try to make the query, and it prints data. I want to detect if it receives any data, because if not I want it to do an insert later.
$sql = "SELECT id_oferta,id_usuario FROM historial WHERE id_oferta = ? AND id_usuario = ?";
$stmt = $this->conn->prepare($sql);
$stmt->bind_param('ii',$id_oferta,$id_usuario);
$stmt->execute();
$stmt->bind_result($oferta,$usuario);
$stmt->fetch();
$row_cnt = $stmt->num_rows;
printf("Result set has %d rows.\n", $row_cnt);
$stmt->close();
$this->conn->close();
Varies a bit using prepared statements: mysqli_stmt::$num_rows