来自codeigniter

时间:2016-05-30 10:25:10

标签: php mysql codeigniter

我知道上述问题有多个教程和stackoverflow答案。但没有人帮忙。

从我的控制器我将数据作为数组传递。 现在创建的存储过程看起来像这样

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

这里rm_id_val是OUT参数,其余是IN

我将$ data数组传递给模型,模型看起来像这样

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

不用说它没用。然后我尝试使用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;

再没有输出。

然后我尝试了MySql Console并执行了以下

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

这导致了

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

请帮我通过codeigniter调用此proc 谢谢和赞赏

1 个答案:

答案 0 :(得分:1)

您是否尝试过设置mysql变量。 尝试使用这种语法将php变量赋值/转换为mysql变量。

SET @running_sum = 0;

在CI中使用一组语法,

$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()");