2

I Know there are multiple tutorials and stackoverflow answer for the said Question. But none helped.

From my controller I am passing my data as an array. Now the Stored Procedure created looks like this

BEGIN

DECLARE recCnt Int DEFAULT 0;
#DECLARE rm_id_val Bigint(19);
select count(*) into recCnt from users where user_name = user_name_in;
IF recCnt > 0 THEN
SET rm_id_val = 0;
ELSE

#SET rm_id = rm_id_gen();

INSERT INTO users(user_category, user_name, facebook_id, 
password, email, mobile_no, city_name, country_name, view_count, user_type, signup_date, updated_on) 
values (user_cat_in,user_name_in, facebook_id_in,
        password_in, email_in, mobile_no_in, city_name_in, country_name_in, 0, user_type_in, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());

select rm_id into rm_id_val from users where user_name=user_name_in;

INSERT INTO activation (rm_id, no_of_attempt, activation_key, activation_status)
VALUES (rm_id_val,0, activation_key_in, 0);
END IF;
END

Here rm_id_val is OUT param and rest are IN

I passed the $data array to model and the model looks like this

    $sql = "CALL signup";
    $query = $this->db->query($sql, $data);
    return $query->result();

Needless to Say It did not work. Then I tried using a solution from stackoverflow

    $this->db->trans_start();
    $p1 = $data['user_cat_in'];
    $p2 = $data['user_name_in'];
    $p3 = $data['facebook_id_in'];
    $p4 = $data['password_in'];
    $p5 = $data['email_in'];
    $p6 = $data['mobile_no_in'];
    $p7 = $data['city_name_in'];
    $p8 = $data['country_name_in'];
    $p9 = $data['view_count'];
    $p10 = $data['user_type_in'];
    $p11 = $data['signup_date'];
    $p12 = $data['updated_on'];
    $success = $this->db->query("CALL signup('$p1','$p2','$p3','$p4','$p5','$p6','$p7','$p8','$p9','$p10',@rm_id_val);");
    print_r("CALL signup('$p1','$p2','$p3','$p4','$p5','$p6','$p7','$p8','$p9','$p10',@rm_id_val);"); exit();
    $out_param_query = $this->db->query('select @rm_id_val as out_param;');
    $this->db->trans_complete();
    return $success;

Well No output again.

Then I tried MySql Console and executed the following

CALL        signup('musician','acacascsacsca','0','cascsacsac','ascascascacacac','acacac','acascacsacs','India','0','1',@rm_id_val);
select @rm_id_val as rmid;

This resulted in

#1414 - OUT or INOUT argument 1 for routine ragamixdb.signup is not a variable or NEW pseudo-variable in BEFORE trigger 

Please help me to get this proc called via codeigniter Thanks and appreciated

0

1 Answer 1

1

Had you tried to set mysql variables. try to assign/convert php variable to mysql variable using this syntax.

SET @running_sum = 0;

use set of syntaxs in CI like this ,

$this->db->query("SET @your_mysql_variable = ".$your_php_variable);

$this->db->query("SET @your_another_mysql_variable = ".$your_another php_variable);

$this->db->query("CALL your_procedure()");
Sign up to request clarification or add additional context in comments.

1 Comment

I will try that--but can you tell me, why mysql console is giving me the error? is the SP correct ? Also please elaborate why i need to set mysql variables to PHP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.