我正在使用最新的 codeigniter 并尝试从我的模型中调用存储过程。我还使用 mysqli 作为数据库驱动程序。现在调用两个存储过程时出现错误。以下是错误:
Error Number: 2014
Commands out of sync; you can't run this command now
call uspTest();
Filename: E:\wamp\www\reonomy-dev\system\database\DB_driver.php
Line Number: 330
请注意,当我调用单个存储过程时,它工作正常。这是模型的代码。
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();
}
}
这是来自 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核心的解决方案??
最佳答案
我关注了 Tim Brownlaw 先生的博客:
http://ellislab.com/forums/viewthread/73714/#562711
首先,修改application/config/config.php,第55行。
$db['default']['dbdriver'] = 'mysqli'; // USE mysqli
然后,将以下内容添加到 mysqli_result.php 中,由于某些奇怪的原因(在/system/database/drivers/mysqli/mysqli_result.php 下)缺少此命令。
/**
* Read the next result
*
* @return null
*/
function next_result()
{
if (is_object($this->conn_id))
{
return mysqli_next_result($this->conn_id);
}
}
然后,在您的模型中,添加 $result->next_result()
。
下面是我的例子。
function list_sample($str_where, $str_order, $str_limit)
{
$qry_res = $this->db->query("CALL rt_sample_list('{$str_where}', '{$str_order}', '{$str_limit}');");
$res = $qry_res->result();
$qry_res->next_result(); // Dump the extra resultset.
$qry_res->free_result(); // Does what it says.
return $res;
}
关于mysql - 在 codeigniter 中调用存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7767231/