【问题标题】:Stored Procedures using CodeIgniter使用 CodeIgniter 的存储过程
【发布时间】:2012-01-19 15:31:26
【问题描述】:

您能否就如何使用 CodeIgniter 框架执行存储过程提供建议?我查看了用户指南,只能找到使用查询或 ActiveRecords 访问数据库的方法。不胜感激,如果有人能尽早提供帮助。

【问题讨论】:

    标签: php codeigniter activerecord stored-procedures


    【解决方案1】:

    您可以使用$this->db->query("call my_stored_proc('arg1','arg2');")

    如果您有 out 参数,则必须将其包装在事务中,如下所示:

    $this->load->database();
    $this->db->trans_start();
    
    $success = $this->db->query("call my_stored_proc('arg1','arg2',@out_param);");
    $out_param_query = $this->db->query('select @out_param as out_param;');
    
    $this->db->trans_complete();
    
    $out_param_row = $this->db->row();
    $out_param_val = $this->out_param;
    

    【讨论】:

    • 这也能帮助我检索多行吗?
    • 如果内部有 select 语句,则可以从存储的 proc 调用中获取多行,但是,如果内部有多个 select 语句,您可能只会得到一组,IIRC 它使用 mysqli_query而不是mysqli_multi_query
    猜你喜欢
    • 2023-04-04
    • 2012-02-21
    • 2015-11-11
    • 2019-11-11
    • 2011-12-07
    • 2016-01-11
    • 1970-01-01
    • 2012-09-02
    相关资源
    最近更新 更多