こんにちは、いくつかのphpクラスがあります。そして、MySql データベースへの接続を渡しています。最初のクラスのインスタンスを作成し、メソッド getinvoicedetails() を使用して請求書クラスを呼び出そうとすると、「コマンドが同期されていません。このコマンドを実行できません」というエラーが表示されます。
どんな助けでも大歓迎です。
コードは次のとおりです。
<?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;
}
}
?>
そして、これが請求書クラスです
<?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();
}
}
?>