【问题标题】:store produre is not getting connection for running another query存储过程未获得运行另一个查询的连接
【发布时间】:2017-05-11 05:47:40
【问题描述】:

我在 codeigniter 中使用 mysql 版本,并将存储过程应用于数据库操作之一,并在运行此之后。我想运行另一个查询。那么如何在存储过程下运行其他查询或关闭连接

收到此错误

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

这是附加代码

这是我的存储过程

$ret = $CI->db->query("call test_type($item_id,$test_id)");
now I want to run this query
$query = $CI->db->query("SELECT * FROM testing WHERE testing.test_type in  ('" . $test_id . "') AND testing.test_item_id =  '" . $item_id . "' ORDER BY testing.test_date DESC LIMIT 1");

提前致谢

【问题讨论】:

  • 请出示所有相关代码。
  • 这是我的存储过程 $ret = $CI->db->query("call test_type($item_id,$test_id)");现在我想运行这个查询 $query = $CI->db->query("SELECT * FROM testing WHERE testing.test_type in ('" . $test_id . "') AND testing.test_item_id = '" . $item_id 。 "' ORDER BY testing.test_date DESC LIMIT 1");
  • 您还应该更新您的问题,而不是在 cmets 中发布其他代码。很不可读。

标签: php mysql codeigniter stored-procedures


【解决方案1】:

试试这个。

参考link。我也遇到像你一样的错误,用下面的代码解决了。

将以下代码添加到/system/database/drivers/mysqli/mysqli_result.php

 function next_result()
 {
     if (is_object($this->conn_id))
     {
         return mysqli_next_result($this->conn_id);
     }
 }

然后在模型中调用存储过程

$sql    = $this->db->query("CALL getCityList()");
$result      = $sql->result();

//add this two line 
$sql->next_result(); 
$sql->free_result(); 
//end of new code

return $result;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 1970-01-01
    相关资源
    最近更新 更多