How to call a MYSQL stored procedure from PHP?

0

I would like to know how to call a stored procedure of Mysql from PHP , I have tried it in several ways but of none I have given and I searched the Internet and neither. I tried it as a simple query like this:

$cal = $_POST['calcular'];
if (isset($cal)) {
   $query = "call CalificaMejor();";
   $datos = mysqli_query($conexion, $query);
}

Thank you very much in advance.

    
asked by El Mago de as 02.01.2018 в 20:55
source

2 answers

1

Replace

$cal = $_POST[ calculate ];

for

$cal = $_POST['calcular'];

You have bad quotes and that's why it does not throw any errors. It is also a good practice to test the variables always with var_dump (); or use some extension of "debugging" php like firePHP for example.

That's it. A greeting

    
answered by 02.01.2018 / 23:36
source
2

For those who do not give, here is the code of how I did to click on calculate I will execute the stored procedure.

if (isset($_POST['calcular'])) {
                            //calcular es el nombre del boton
                            $stmt = $conexion->prepare("CALL CalculaMejor();");
                            $stmt->execute();
                            if ($stmt == false) {
                                echo("Error! Al calcular mejor.");
                                $stmt->close();
                            } else {
                                echo("Exito! Calculo exitoso.");
                                $stmt->close();
                            }
                        }
    
answered by 02.01.2018 в 23:53