从 CodeIgniter 的 Active Record 类调用存储过程 [英] Calling a stored procedure from CodeIgniter's Active Record class

查看:28
本文介绍了从 CodeIgniter 的 Active Record 类调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 CI 应用程序 设置中查询 mssql 数据库.我想从 active record 执行一个 stored procedure.但是我找不到任何可靠的文档.

In my CI application setup to query a mssql database. I want to execute a stored procedure from active record. But I can't get hold of any solid documentation.

有没有人有使用 CodeIgniter 和/或 Active Record 调用存储过程并传入参数的经验?

Does anyone have any experience with calling stored procs with CodeIgniter and/or Active Record and passing in parameters?

谢谢,

比利

推荐答案

是的,在你的模型中试试这个.

Yes , try this in your model.

$this->db->query("call {storedprocedure function name} ");

如果您在一次调用多个存储过程时遇到问题,则需要添加以下行

if you encounter trouble calling more than 1 stored procedure at a time you need to add the following line

/* ADD THIS FUNCTION IN SYSTEM/DATABASE/DB_ACTIVE_REC */
/* USAGE $this->db->freeDBResource($this->db->conn_id); */
function freeDBResource($dbh){
    while(mysqli_next_result($dbh)){
            if($l_result = mysqli_store_result($dbh)){
              mysqli_free_result($l_result);
            }
        }
}

这篇关于从 CodeIgniter 的 Active Record 类调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆