I have a question, I am developing a small PHP to obtain the data of a query in a procedure stored in MySQL, the problem is that I can not find a way to detect if this query ended in error, to perform the procedure if necessary corresponding in my PHP. I attach my PHP code, as well as my stored procedure. I am voluntarily making an error in my stored procedure but I can not detect this error in my PHP.
<?php
require_once '../constantes.php';
require_once RUTAS_FICHEROS['FuncionesGenerales'];
$conexion = obtenerConexion();
if ($conexion == FALSE) {
echo "Error de conexión";
} else {
if (!($sqlResultado = $conexion->query("call bd_secjo.test(50);"))) {
echo "Consulta fallida"; //Esta es la parte que no logro detectar, estoy generando un error en mi procedimiento pero no imprime "Consulta fallida"
}
var_dump($sqlResultado->fetch_assoc());
desconectarServer($conexion);
}
My stored procedure:
CREATE DEFINER='Cliente'@'%' PROCEDURE 'test'(num int)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
SHOW ERRORS LIMIT 1;
RESIGNAL;
ROLLBACK;
END;
DECLARE EXIT HANDLER FOR SQLWARNING
BEGIN
SHOW WARNINGS LIMIT 1;
RESIGNAL;
ROLLBACK;
END;
START TRANSACTION;
insert into tblcargos (Cargo) values(num);
select * from tblcargoss; //aquí genero un error voluntario
COMMIT;
END
When doing vardump in PHP, print the following:
array(3) { ["Level"]=> string(5) "Error" ["Code"]=> string(4) "1146" ["Message"]=> string(41) "Table 'bd_secjo.tblcargoss' doesn't exist" }