0

我在 Codeigniter 中使用这个库从存储过程中检索多个结果集:

class Multi_Results
{
   private $CI, $Data, $mysqli, $ResultSet;

   /**
   * The constructor
   */

   function __construct()
   {
     $this->CI =& get_instance();
     $this->Data = '';
     $this->ResultSet = array();
     $this->mysqli = $this->CI->db->conn_id;
   }

    public function GetMultiResults($SqlCommand)
    {
        /* execute multi query */
        if (mysqli_multi_query($this->mysqli, $SqlCommand)) {
            $i=1;
            do
            {
                if ($result = $this->mysqli->store_result()) 
                {
                    while ($row = $result->fetch_assoc())
                    {
                        $this->Data[$i][] = $row;
                    }
                    mysqli_free_result($result);
                }
                $i++; 
            }
            while ($this->mysqli->more_results() && $this->mysqli->next_result());
        }
        return $this->Data;
    }

}

我正在从控制器调用程序,例如

$result_array = $this->multi_results->GetMultiResults("CALL procedure_name($input_1, '$input_2')");

它做它应该做的事情。当我一个接一个地从控制器调用 2 个不同的过程并将结果分配给不同的变量时,就会出现问题。当我 var_dump 第二个(最后一个)结果时,它还包含第一个结果的结果集。我已经检查了 database.php 中的连接 dbdriver(它设置为 MSQLI),我尝试实施一些建议,例如: CodeIgniter active records' questions called multiple stored proceduresCalling a stored procedure from CodeIgniter's Active Record class 他们都提出了解决方案使用 'mysqli_free_result' 但是,这已经在插件库中完成(如您在上面的代码片段中所见)。

任何建议将不胜感激!

4

1 回答 1

1

启动$this->data = ''函数 GetMultiResults() 而不是构造函数。我认为这将解决您的问题。

于 2017-06-07T14:39:55.563 回答