CodeIgniter Forums
Error in Model to Call Stored Procedure MYSQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Error in Model to Call Stored Procedure MYSQL (/showthread.php?tid=73575)



Error in Model to Call Stored Procedure MYSQL - gilgustavoj - 05-10-2019

I have the following error when executing an SP in my model:

Code:
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:


Code:
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;
        }else{
            return false;
        }

    }

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

Code:
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.


RE: Error in Model to Call Stored Procedure MYSQL - InsiteFX - 05-11-2019

Should this be like

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

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