【问题标题】:How to use two or more stored procedures in codeigniter code?如何在 codeigniter 代码中使用两个或多个存储过程?
【发布时间】:2018-04-07 10:47:56
【问题描述】:

我正在处理Codeigniter 项目,我正在使用stored procedures 进行后端操作。当我对SELECT 语句使用单个stored procedure 时,它会正常工作。但是当我尝试为相同的操作调用两个或多个stored procedures 时,它会给我一个错误。

错误:

发生数据库错误

错误号:2014

命令不同步;你现在不能运行这个命令

调用 all_Cluster()

文件名:C:/xampp/htdocs/prop/system/database/DB_driver.php

行号:691

这是我的代码:

型号:

public function getProperty()
    {
        $query = $this->db->query('call select_prop_SP()');
        // if ($query->num_rows() > 0) {
        return $query->result();
        $query->next_result(); 
        $query->free_result();
    }
public function area()
    {
         $query = $this->db->query('call select_area_SP()');
        // if ($query->num_rows() > 0) {
        return $query->result();
        $query->next_result(); 
        $query->free_result();
    }
public function cluster()
    {
        $query = $this->db->query('call select_Cluster_SP()');
        // if ($query->num_rows() > 0) {
        return $query->result();
        $query->next_result(); 
        $query->free_result();
    }

这是我的 SP:

select_area_SP

BEGIN
SELECT `area_id`, `area_name`, `area_status` FROM `tbl_area`;
END

select_Cluster_SP

BEGIN
SELECT `cluster_id`, `cluster_name`, `area_id`, `cluster_status` FROM `tbl_cluster`;
END

我已经用谷歌搜索了很长时间,但我还没有发现任何积极的结果。 我已经通过Calling stored procedure in codeigniter 并进行所有更改,但没有成功。

感谢任何形式的帮助。提前致谢。

【问题讨论】:

标签: php mysql codeigniter stored-procedures


【解决方案1】:

next_resultfree_result 函数未执行,因为 return 语句退出函数。您必须在返回之前将结果存储在临时变量中:

public function cluster()
{
        $query = $this->db->query('call select_Cluster_SP()');
        $result = $query->result();
        $query->next_result(); 
        $query->free_result();
        return $result;
}

或将您的配置更改为 mysqli 驱动程序,该驱动程序在每次存储过程调用后包含 next_result 函数:

$db['default']['dbdriver'] = 'mysqli';

【讨论】:

  • 看起来它给出了一个错误Call to undefined method CI_DB_mysqli_result::next_result()
猜你喜欢
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 2017-02-27
  • 2019-10-28
  • 2013-08-02
  • 2021-09-24
  • 2016-09-26
  • 1970-01-01
相关资源
最近更新 更多