1

So before it not error like this, but when I have been created two stored procedure in my database and call it in my model. It error another function in my model. It not error the function that I call procedure. It error another function that I write raw sql in model (Codelgniter).

My Error

enter image description here

My Model

public function CheckProductInsert($company_id,$purchase_or_id,$product_id,$supplier_id){
    $company_id = $this->db->escape_str($company_id);
    $purchase_or_id = $this->db->escape_str($purchase_or_id);
    $product_id = $this->db->escape_str($product_id);
    $supplier_id = $this->db->escape_str($supplier_id);
    $k="SELECT id 
            FROM gacc_purchases_or_details 
            WHERE 
                purchase_or_id=$purchase_or_id 
                AND product_id=$product_id
                AND supplier_id=$supplier_id
                AND company_id=$company_id
                AND activate=1";
    $re = $this->db->query($k);
    if($re->num_rows() > 0){
        return true;
    }else{
        return false;
    }
}

My Controller

if($this->PurchaseOrders->CheckProductInsert(
                                                $this->security->xss_clean($this->company_id),
                                                $this->security->xss_clean($purchase_order_id),
                                                $this->security->xss_clean($product_id),
                                                $this->security->xss_clean($supplier_id)
                                            )==false){
                        echo json_encode(
                                        array(
                                            'status'=>false,
                                            'message'=>'good job' 
                                        )
                                    );                      
                    }else{
                        if($lang=='EN'){
                            echo json_encode(
                                            array(
                                                'status'=>false,
                                                'message'=>'This product you have been add already.'
                                            )
                                        );
                        }else{
                            echo json_encode(
                                            array(
                                                'status'=>false,
                                                'message'=>'ផលិតផល ដែលលោកអ្នករក្សាទុក បានបញ្ចូលរួចហើយ'
                                            )
                                        );
                        } 
                    }
Ah Hea Sk
  • 13
  • 1
  • 2
  • 4
  • Possible duplicate of [codeigniter : Commands out of sync; you can't run this command now](https://stackoverflow.com/questions/43232250/codeigniter-commands-out-of-sync-you-cant-run-this-command-now) – Brian Gottier Jan 15 '18 at 05:23

1 Answers1

3

If you used Stored Procedure earlier in this code then this may be the solution

For reference - link

solution :

add following code into /system/database/drivers/mysqli/mysqli_result.php

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

then in model when you call Stored Procedure

$query    = $this->db->query("CALL test()");
$res      = $query->result();

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

return $res;

or else if you dont want to edit the system files then try this in model when you call Stored Procedure

mysqli_next_result( $this->db->conn_id );
$query->free_result(); 
Anu
  • 556
  • 6
  • 20