I have the following code to consult the database:
<?php
include_once '__conexion.php';
require "funciones/JSON.php";
?>
<?php
$cedula = 111111; //No existe
$estado=1;
//-- Obtener Ultimo ID de sancion registrado para ese sancionado --//
$stmt = $conexion->prepare("SELECT max(id_omd) FROM sanciones WHERE cedula_sancionado = ? AND estado_sancion_id = ?");
var_dump($stmt)."<br>";
$stmt->bind_param("ii", $cedula, $estado);
$stmt->execute();
$stmt->store_result();
$cantidad=$stmt->num_rows;
var_dump($cantidad);
$stmt->bind_result($ultimoregistro);
$stmt->fetch();
if ($stmt->num_rows === 0) {
echo "No registro";
} else {
echo "Si hay registros";
}
The problem : In the database there is NO record with this data Making the query in phpMyAdmin you get a NULL value:
max(id_omd)
NULL
When I use var_dump($canrtidad)
; returns int(0)
.
But the query continues as if there are records, invalidating $stmt->num_rows===0