0

The code brings the corresponding parameters and does not show any error or exception, I have no idea why it does not perform what is programmed in the stored procedure, help!

This is the stored procedure in MySQL:

DELIMITER //
DROP PROCEDURE IF EXISTS prueba.CAMBIA_A_ACTIVO //
CREATE PROCEDURE CAMBIA_A_ACTIVO
( 
    IN  _email VARCHAR(45),
    IN _nombre_grupo VARCHAR(80)
) 
BEGIN
 UPDATE INTEGRATES_GRUPOS SET activo = 1
 WHERE nombre_grupo = _nombre_grupo 
 AND email = _email;
END; //  

And this is the php code:

<?php

require_once('connection.php');

class CAMBIA_A_ACTIVO
{
    public function __construct($email, $nombre_grupo)
    { 
        try
            { 
                $mysql = new connection();
                $conexion = $mysql -> get_connection(); 
                $datos = array("email" => "$email", "nombre_grupo" => "$nombre_grupo"); 
                $statement = $conexion->prepare("CALL CAMBIA_A_ACTIVO(?,?)"); 
                $statement -> bind_param("ss", $datos["email"], $datos["nombre_grupo"]); 
                $statement -> execute(); 
                $statement -> close();
                $conexion -> close();   
            } catch (Exception $e)
                  {echo $e->getMessage();}
    }
}
?>
Barmar
  • 669,327
  • 51
  • 454
  • 560

1 Answers1

0

There are certain points within the exection flow where you can test for success or failure - as the code is set to catch Exceptions you could use such logic tests to raise new exceptions if there is a problem.

Presumably the actual stored procedure works when called from either the commandline or gui?

<?php
    require_once('connection.php');
    class CAMBIA_A_ACTIVO {
        public function __construct($email, $nombre_grupo){ 
            try { 
                $mysql = new connection();
                $conexion = $mysql->get_connection(); 

                if( $conexion ){
                    $datos = array("email" => "$email", "nombre_grupo" => "$nombre_grupo"); 
                    $statement = $conexion->prepare("CALL CAMBIA_A_ACTIVO(?,?)");

                    if( !$statement )throw new Exception('Failed to prepare SQL statement');
                    else {

                        $statement->bind_param("ss", $datos["email"], $datos["nombre_grupo"]); 
                        $result=$statement->execute();
                        $statement->close();
                        $conexion->close();

                        if( !$result )throw new Exception('Query failed');
                    }
                } else {
                    throw new Exception('Connection to db failed');
                }
            } catch (Exception $e){
                echo $e->getMessage();
            }
        }
    }
?>
Professor Abronsius
  • 30,177
  • 5
  • 29
  • 43