0

I'm using this library in Codeigniter to retrieve multiple result sets from stored procedures :

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;
    }

}

I'm calling the procedure from the controller like

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

It does what it is supposed to do. The problem arises when I call 2 DIFFERENT procedures from the controller one after another and assign the results to different variables. When I var_dump the second (last) result, it contains also the result set from the 1st result. I have checked the connection dbdriver in database.php (it is set to MSQLI), I tried to implement some suggestions like : CodeIgniter active records' problems calling multiple stored procedures and Calling a stored procedure from CodeIgniter's Active Record class They both propose a solution with 'mysqli_free_result' however that is already done in the addon library (as you can see in the code snippet above).

Any suggestion will be highly appreciated!

dujmovicv
  • 65
  • 12

1 Answers1

1

Initiate $this->data = '' into the function GetMultiResults() instead into constructor. I think this will solve your problem.