【问题标题】:Commands out of sync; you can't run this command now while calling stored procedure in Mysql命令不同步;在 Mysql 中调用存储过程时,您现在无法运行此命令
【发布时间】:2012-03-27 17:01:13
【问题描述】:

我正在尝试运行一个程序,但出现此错误

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

这是我得到的原始错误

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

SELECT DISTINCT `property_id`, `pin`, `block_id`, `serial_no`, `status`, `ex_sn`, `ex_code`, `property_date_time`, `street_add`, `lab_name` FROM `view_property_user_lab` WHERE status = '6' AND lab_id = '01' AND designation IN( '5','6') LIMIT 10 

谁能告诉我为什么我会收到这个错误以及如何摆脱它。我正在使用代码点火器,我也尝试过这个

$query->free_result().

在我的程序中我使用了这个语句

   SELECT *
   FROM
  temp_calculated_rates_and_rules;
 -- and then
   TRUNCATE temp_calculated_rates_and_rules;

因为这个东西在 PHP Loop 中被称为是这样的

  $arrIds = array('5','10');
    foreach ($arrIds as $id)
    {
        $this->_StoredProcedureMapper->setPId($id);

        $p10values = $this->_StoredProcedureMapper->fetch_p10_values();
        if (intval(@$p10values[0]['is_exempted']) != 1)
        {
            $this->generate_p10($p10values);
        }

    }

这里是映射器函数

    function fetch_p1_values()
{

    $qry = "CALL sp_main_pt10(?)";
    $result = $this->db->query($qry, $this->getPId());
    return $result->result_array();
}

我正在使用“mysqli”驱动程序

【问题讨论】:

  • 这就是你的全部 SQL 吗?您是否同时运行任何其他查询?在未开启多查询模式的情况下调用存储过程或执行多查询时最常看到此错误。
  • 是的,非常正确,我正在运行多个查询,但我只粘贴了实际显示错误的 1
  • 你能发布以前的查询,也许是运行它们的 PHP 吗?您发布的查询没有任何问题;当您尝试执行 MySQL 会话时,它的状态存在问题。
  • 我认为当我尝试在循环中点击该过程时会出现此问题。对于单次点击它工作正常,实际上这里有两种情况,当我尝试从程序返回一些结果时,我得到了错误。
  • 另一种情况是我没有从任何程序返回。

标签: php mysql codeigniter stored-procedures


【解决方案1】:

因此您需要处理存储过程生成的额外结果集。 mysqli 驱动程序为此提供了一种方法,但 CodeIgniter 可能无法使该方法可用。

来自https://ellislab.com/forums/viewthread/73714/#562711

我只是将以下内容添加到缺少的 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() 来释放 预期的无关结果集。

【讨论】:

  • 过去 2 小时内我一​​直在解决此问题。有很多类似的问题,但大多数解决方案都没有 CI。这对我来说非常有效。谢谢你瑞恩!
猜你喜欢
  • 2019-03-05
  • 2019-04-25
  • 2012-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
  • 1970-01-01
  • 2013-08-29
相关资源
最近更新 更多