在代码中调用存储过程

问题描述:

我使用最新的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

Error Number: 2014

命令不同步;您现在无法运行此命令

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

调用uspTest();

call uspTest();

文件名:E:\wamp \www\reonomy-dev\system\database\DB_driver.php

Filename: E:\wamp\www\reonomy-dev\system\database\DB_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();
}

}

/ p>

Here is the code from controller

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.