CodeIgniter Forums

Full Version: Error in Model to Call Stored Procedure MYSQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the following error when executing an SP in my model:

A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,?,?,?,?,?,?,?,?,@estado,@msg)' at line 1
CALL sp_nuevo_usuario_no_pre_cargado(?,?,?,?,?,?,?,?,?,?,?,@estado,@msg)
Filename: models/Welcome_model.php
Line Number: 237

And this is my model:

public function nuevoUsuarioNoPreCargado($nombres = null, $apellidos = null, $codigo = null, $rut = null, $correo = null, $fecha_nacimiento = null, $sexo = null, $privilegios_id = null, $codigo_jefe = -1, $password = null, $hash = null){
        $sql = 'CALL sp_nuevo_usuario_no_pre_cargado(?,?,?,?,?,?,?,?,?,?,?,@estado,@msg)';
        $query = $this->db->query($sql,array($nombres,$apellidos,$codigo,$rut,$correo,$fecha_nacimiento,$sexo,$privilegios_id,$codigo_jefe,$password,$hash));

        $sql_2 = 'SELECT @estado AS estado, @msg AS msg';
        $query_2 = $this->db->query($sql);

        if($query != null && $query != false && $query_2 != null && $query_2 != false){
            return $query_2->row()->estado;
            return false;


But if, i remove the @ from the output parameter, this is the response:

A Database Error Occurred
Error Number: 1414
OUT or INOUT argument 12 for routine be_fsc.sp_nuevo_usuario_no_pre_cargado is not a variable or NEW pseudo-variable in BEFORE trigger
CALL sp_nuevo_usuario_no_pre_cargado('asdas','dasda','123456','44231234','[email protected]','2019-05-09','Masculino','2',-1,'123456789','9946c3cff71715a3f2d99ad6642c121b0a191edc',estado,msg)
Filename: models/Welcome_model.php
Line Number: 234

The Stored Procedure Work fine in mysql shell and passing parameter manually.
Should this be like

PHP Code:
$query_2 $this->db->query($sql);

$query_2 $this->db->query($sql_2);