在codeigniter中调用存储过程 [英] Calling stored procedure in codeigniter

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

问题描述

我正在使用最新的 codeigniter 并尝试从我的模型中调用存储过程.我也使用 mysqli 作为数据库驱动程序.现在我在调用两个存储过程时出错.以下是错误:

I am using latest codeigniter and trying to call stored procedure from my model. Also I am using mysqli as database driver. Now I am having an error when I call two stored procedures. Following is the error:

错误编号:2014

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

Commands out of sync; you can't run this command now

调用uspTest();

call uspTest();

文件名:E:wampwww eonomy-devsystemdatabaseDB_driver.php

Filename: E:wampwww eonomy-devsystemdatabaseDB_driver.php

行号:330

请注意,当我调用单个存储过程时,它工作正常.这是模型的代码.

Note that when I call a single stored procedure it works fine. Here is the code for model.

class Menus_model extends CI_Model {

function __construct()
{
    parent::__construct();

}

public function getMenus()
{
    $query = $this->db->query("call uspGetMenus()");

    return $query->result();
}

public function getSubMenus()
{
    $query = $this->db->query("call uspTest()");
    return $query->result();
}

}

这是控制器的代码

class MYHQ extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->model('menus_model');
}

public function index()
{
    $menu = $this->menus_model->getMenus();
    $submenu = $this->menus_model->getSubMenus();
}

}

有没有不破解codeigniter核心的解决方案??

Is there any solution without hacking the core of codeigniter??

推荐答案

这似乎是 CodeIgniter 中的一个错误.我想不到它怎么还在里面.但是,有几种方法可以克服它.

This seems to be a bug in CodeIgniter. How come it's still in there is beyond me. However, there's a couple of ways to overcome it.

在这里查看:http://codeigniter.com/forums/viewthread/73714/基本上,您修改 mysqli_result.php 以包含 next_result() 函数并确保在每个存储过程之后调用它.称呼.请注意,它假定您使用 mysqli 作为您的数据库驱动程序......但您可能可以用任何其他方式做类似的事情.您可以在/application/config/database.php 中更改您的驱动程序

Check here: http://codeigniter.com/forums/viewthread/73714/ Basically, you modify mysqli_result.php to include next_result() function and make sure to call it after every stored proc. call. Just note that it assumes you're using mysqli as your DB driver... but you can probably do something similar with any other. You can change your driver in /application/config/database.php It's the line that says

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

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

默认.改为:

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

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

您也可以关闭/重新打开调用之间的数据库连接,但我绝对建议不要使用这种方法.

You could also just close/reopen a DB connection between the calls, but I would definitely advise against that approach.

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

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