Hi I have a couple of php classes. And I am passing a connection to a MySql database. When I make an instance of the firs class and try to call the invoice class with the method getinvoicedetails() I get error "Command out of sync; you can't run this command".
Any help wil be appreciated.
Here is the code:
    <?php //Invoicectrl class
    class invoicectrl
{
    // define properties
     public $invoices = Array();
     public $connection;
     public $userID;
     public $ownerID;
    // constructor
    public function __construct($userIDin,$ownerIDin) {
        $this->userID = $userIDin;
        $this->ownerID = $ownerIDin;
    }
     //function to set connection to db
    public function setconnection($conn){
        $this->connection = $conn;
    }
    public function getinvoicelist(){
        $res = Array();
        $invIDs = Array();
        //Get list of invoicenumbers and invoiceIDs
        $queryd = "CALL sp_getOwnersInvNumIDs (".$this->ownerID.")";
        $result = $this->connection->query($queryd) or die($this->connection->error.__LINE__);
        // GOING THROUGH invoices and getting there data
        $o=0;
        while($row = $result->fetch_assoc()) {
           $invIDs[$o]['ID'] = $row['invoiceID'];
           $invIDs[$o]['NR'] = $row['invoicenumber'];                               }
                   $result->free();
                   //Set each invoice own info
                   for($i=0;$i<=count($invIDs)-1;$i++){
                      $res[$i] = new invoice($invIDs['ID'],$invIDs['NR']);
                      $res[$i]->setconnection($this->connection);
           $res[$i]->getinvoicedetails();
                   } 
        return $res;
    }
}
?>
And here is the invoice class
    <?php //Invoice class
    class invoice
{
    // define properties
     public $invoiceID;
     public $invoicenumber;
     public $itemIDs=Array();
     public $items= Array();
     public $customerID;
     public $cust_company;
     public $cust_name;
     public $cust_email;
     public $cust_adress1;
     public $cust_adress2;
     public $cust_adress3;
     private $connection;
    // constructor
    public function __construct($invoiceIDin,$invoicenumberin) {
        $this->invoiceID = $invoiceIDin;
        $this->invoicenumber = $invoicenumberin;
    }
    //function to set connection to db
    public function setconnection($conn){
        $this->connection = $conn;
    }
        //sets all invoices details
    public function getinvoicedetails(){
                  //Get customer on invoice
                    $queryd = "select customerID FROM Accounting_Invoice_Customer where invoiceID =".$this->invoiceID."";
        $result = $this->connection->query($queryd) or die($this->connection->error.__LINE__);
                   while($row1 = $result->fetch_assoc()) {
            $this->customerID = $row1['customerID'];
                   }
                   $result->free();
                    //Get list of items on invoice
        $queryd = "call sp_getItems(".$this->invoiceID.")";
        $result = $this->connection->query($queryd) or die($this->connection->error.__LINE__);
        $o=0;
                   while($row2 = $result->fetch_assoc()) {
            $this->items[$o]['itemID'] = $row2['itemID'];
            //$this->items[$o]['itemnumber'] = $row['itemnumber'];
            //$this->items[$o]['itemdescription'] = $row['itemdescription'];
            //$this->items[$o]['itempricewotax'] = $row['itempricewotax']; 
            $o++;
        }       
                   $result->free(); 
    }
}
?>
 
    